Exercise - Create an Azure Kubernetes Service cluster
In this exercise, create an AKS cluster that uses several nodes to meet the demand of many customers using the service. You decide to use the single control plane and multiple nodes architecture because it provides the best way to create and manage workload resources.
AKS supports both Linux and Windows node pools via the Portal or Azure CLI. However, if you're going to use Windows node pools, the cluster must be created with extra prerequisites and commands. Select an OS based on which type of node pools you want to add.
Important
You need your own Azure subscription to complete this exercise, and you might incur charges. If you don't already have an Azure subscription, create a free account before you begin.
Sign in to Azure Cloud Shell with the account you want to deploy resources into.
Important
We'll run all the scripts with Bash, so if you haven't created a Cloud Shell yet, select Bash as the running shell.
In the Cloud Shell window, select Settings > Go to Classic version.
Create variables for the configuration values you reuse throughout the exercises.
export RESOURCE_GROUP=rg-contoso-video export CLUSTER_NAME=aks-contoso-video export LOCATION=eastusUpdate the LOCATION variable with the region closest to you. This example uses:
eastus.Run the
az group createcommand to create a resource group. Deploy all resources into this new resource group.az group create --name=$RESOURCE_GROUP --location=$LOCATIONRun the
az aks createcommand to create an AKS cluster.az aks create \ --resource-group $RESOURCE_GROUP \ --name $CLUSTER_NAME \ --node-count 2 \ --generate-ssh-keys \ --node-vm-size Standard_B2s \ --network-plugin azureThe command creates a new AKS cluster named
aks-contoso-videowithin therg-contoso-videoresource group. The cluster has two nodes defined by the--node-countparameter. We're using only two nodes in this exercise for cost considerations in this exercise. The--node-vm-sizeparameter configures the cluster nodes as Standard_B2s-sized VMs. These nodes are part of System mode.Important
Standard B2s VMs are required to create node pools but not available in Free-Tier subscriptions. If you're receiving notifications about limits, you need to upgrade to a Standard Upgrade.
Run the
az aks nodepool addcommand to add another node pool that uses the default Linux operating system.az aks nodepool add \ --resource-group $RESOURCE_GROUP \ --cluster-name $CLUSTER_NAME \ --name userpool \ --node-count 2 \ --node-vm-size Standard_B2sThe command adds a new node pool (User mode) to the existing AKS cluster (created in the previous command). This User node pool is used to host applications and workloads, unlike the System node pool.
Link with kubectl
Link your Kubernetes cluster with
kubectlby running the following command in Cloud Shell.az aks get-credentials --name $CLUSTER_NAME --resource-group $RESOURCE_GROUPThis command adds an entry to your
~/.kube/configfile, which holds all the information to access your clusters. Kubectl enables you to manage multiple clusters from a single command-line interface.Run the
kubectl get nodescommand to check that you can connect to your cluster, and confirm its configuration.kubectl get nodesThe output should list four available nodes for two node pools.