Lab 01: Deploy an OKS Cluster
Learn how to deploy a Kubernetes cluster with OKS and manage your resources…
In this lab, you will learn how to deploy a Kubernetes cluster using our managed solution. You will explore and manage this cluster via the command line using oks-cli. Finally, you will deploy a simple application on Kubernetes.
Lab Architecture
Section intitulée « Lab Architecture »In this section, you will learn how to:
- Configure the
oks-clitool to interact with and manage your Kubernetes cluster. - Configure the
kubectltool to manage the cluster. - Deploy a simple application on the Kubernetes cluster.
- Manage your OKS profiles.
Setting Up a Virtual Environment (venv)
Section intitulée « Setting Up a Virtual Environment (venv) »- Creating the Virtual Environment
To avoid conflicts with system packages, it is recommended to use a Python virtual environment to install oks-cli. Here’s how:
python3 -m venv .venvThis will create a .venv directory where the virtual environment will be stored.
- Activating the Virtual Environment
Then, activate the virtual environment depending on your operating system:
- On Linux or macOS:
source .venv/bin/activate-
On Windows (cmd.exe):
.venv\Scripts\activate.bat
-
On Windows (PowerShell):
.venv\Scripts\Activate.ps1
Once activated, your command prompt will change to display the environment name (e.g., .venv), indicating that you are now working inside this virtual environment.
Installing OKS CLI
Section intitulée « Installing OKS CLI »Once the virtual environment is activated, you can install oks-cli:
pip install https://docs.eu-west-2.oks.outscale.com/oks-cli/oks_cli-latest.zip- Verifying the Installation
To verify that oks-cli was installed successfully, run:
oks-cli versionThis should display the version of the oks-cli tool.
- Viewing all available options
To see all available options:
oks-cli fullhelpGenerating the Autocompletion File
Section intitulée « Generating the Autocompletion File »To generate the autocompletion file for oks-cli, run:
mkdir -p $HOME/.oks_cli/completions/
_OKS_CLI_COMPLETE=bash_source oks-cli > $HOME/.oks_cli/completions/oks-cli.bash
. $HOME/.oks_cli/completions/oks-cli.bashecho '. $HOME/.oks_cli/completions/oks-cli.bash' >> $HOME/.bashrcThis will create a file containing Bash-specific autocompletion rules.
Installing Kubectl
Section intitulée « Installing Kubectl »Once the virtual environment is set up and oks-cli is installed, you can install kubectl to manage your Kubernetes cluster.
- System prerequisites
You must use a version of kubectl that differs by no more than one minor version from your Kubernetes cluster version.
- Installing Kubectl on Linux
To install the latest version of kubectl, use:
curl -LO https://dl.k8s.io/release/$(curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectlIf you want to install a specific version, replace $(curl -Ls https://dl.k8s.io/release/stable.txt) with the desired version number.
For example, to install version 1.32.0:
curl -LO https://dl.k8s.io/release/v1.32.0/bin/linux/amd64/kubectl- Making the binary executable
Once downloaded, make the binary executable:
chmod +x ./kubectl- Moving the binary to your PATH
Move the executable file to a directory in your PATH:
sudo mv ./kubectl /usr/local/bin/kubectl- Verifying the installation
Check that kubectl is installed correctly:
kubectl version --client- Other installation methods
You can also refer to the official Kubernetes documentation for additional installation methods:
https://kubernetes.io/docs/tasks/tools/install-kubectl/
Configuring kubectl
Section intitulée « Configuring kubectl »To make kubectl easier to use, you can configure aliases and autocompletion.
- Configuring an alias for kubectl
Add the following alias to your .bashrc or .zshrc:
alias k='kubectl'Then reload your configuration file:
source ~/.bashrc # or source ~/.zshrc for ZshYou can now use k instead of kubectl.
- Enabling kubectl autocompletion
To enable autocompletion:
-
Install the autocompletion script:
Terminal window $ kubectl completion bash > ~/.kubectl-completion$ source ~/.kubectl-completion -
Add this line to your
.bashrcor.zshrc:source <(kubectl completion bash)
Reload your configuration:
source ~/.bashrc # or source ~/.zshrc for ZshAutocompletion is now enabled.
Managing OKS Profiles
Section intitulée « Managing OKS Profiles »Access to your Kubernetes clusters via oks-cli is organized through profiles. An OKS profile corresponds to an Outscale account associated with projects and clusters, allowing simplified resource management.
- List all available profiles:
oks-cli profile listExample output:
Profile: default Account type: ak/sk Region: eu-west-2 Endpoint: https://api.eu-west-2.oks.outscale.com/api/v2/Profile: my-second-profile Account type: username/password Region: eu-west-2 Endpoint:https://api.eu-west-2.oks.outscale.com/api/v2/- Add an existing profile:
oks-cli profile add --profile-name "my-second-profile" --access-key <ACCESS_KEY> --secret-key <SECRET_KEY> --region eu-west-2You can also add a profile using access and secret keys:
oks-cli profile add --profile-name "my-third-profile" --access-key MY_ACCESS_KEY --secret-key MY_SECRET_KEY --region eu-west-2Profile names must be unique. If omitted, the default profile will be updated.
- Update a profile with a new region and endpoint:
oks-cli profile update --profile-name my-third-profile --region cloudgouv-eu-west-1Managing OKS Projects
Section intitulée « Managing OKS Projects »- List available projects:
oks-cli --profile my-profile project list- Create a new project:
oks-cli --profile my-profile project create --project-name my-project --description 'Lab project'- Get detailed project information:
oks-cli --profile my-profile project get --project-name my-projectCreating and Managing Kubernetes Clusters
Section intitulée « Creating and Managing Kubernetes Clusters »Each cluster in OKS must be associated with a project.
- List clusters:
oks-cli --profile my-profile cluster list --project-name my-project- Create a cluster:
oks-cli --profile my-profile cluster create --project-name my-project --cluster-name my-cluster --admin "xx.xx.xx.xx/xx" --control-plane "cp.mono.master" --version 1.30--cluster-name: Cluster name (unique within the project)--project-name: Target project--admin: Allowed IP(s)--control-plane: Control plane size--version: Kubernetes version
Get your public IP:
curl -4 ifconfig.me- Check cluster status:
oks-cli --profile my-profile cluster list --project-name my-project- Get cluster details:
oks-cli --profile my-profile cluster get --project-name my-project --cluster-name my-cluster- Access the cluster:
oks-cli --profile my-profile cluster kubeconfig --cluster-name my-cluster --project-name my-project > kubeconfig.yamlexport KUBECONFIG=./kubeconfig.yamlTest access:
kubectl get nsCreating a Nodepool
Section intitulée « Creating a Nodepool »Using OKS CLI
Section intitulée « Using OKS CLI »oks-cli cluster nodepool --cluster-name my-cluster --project-name my-project create --nodepool-name my-nodepool --type "tinav6.c4r6p2" --count 3Using Kubernetes manifest
Section intitulée « Using Kubernetes manifest »apiVersion: oks.dev/v1beta2kind: NodePoolmetadata: name: nodepool-01spec: desiredNodes: 2 nodeType: tinav7.c2r4p2 zones: - eu-west-2a upgradeStrategy: maxUnavailable: 1 maxSurge: 0 autoUpgradeEnabled: true autoUpgradeMaintenance: durationHours: 1 startHour: 12 weekDay: Tue autoHealing: trueApply:
kubectl apply -f nodepool.yamlVerify:
kubectl get nodepoolsNode Inspection
Section intitulée « Node Inspection »kubectl get nodeskubectl describe node <node-name>To avoid specifying the project name every time:
oks-cli project login <project-name>