Exercise - Create an Azure Kubernetes Service cluster

Completed

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 run this exercise, and you might incur charges. If you don't already have an Azure subscription, create a free account before you begin.

  1. 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.

  2. 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=eastus
    

    Update the LOCATION variable with the region closest to you. This example uses: eastus.

  3. Run the az group create command to create a resource group. Deploy all resources into this new resource group.

    az group create --name=$RESOURCE_GROUP --location=$LOCATION
    
  4. Run the az aks create command 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 azure
    

    The command creates a new AKS cluster named aks-contoso-video within the rg-contoso-video resource group. The cluster has two nodes defined by the --node-count parameter. We're using only two nodes in this exercise for cost considerations in this exercise. The --node-vm-size parameter 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.

  5. Run the az aks nodepool add command 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_B2s
    

    The 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.

  1. Link your Kubernetes cluster with kubectl by running the following command in Cloud Shell.

    az aks get-credentials --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP
    

    This command adds an entry to your ~/.kube/config file, which holds all the information to access your clusters. Kubectl enables you to manage multiple clusters from a single command-line interface.

  2. Run the kubectl get nodes command to check that you can connect to your cluster, and confirm its configuration.

    kubectl get nodes
    

    The output should list four available nodes for two node pools.

NAME                                STATUS   ROLES   AGE    VERSION
aks-nodepool1-21895026-vmss000000   Ready    agent   245s   v1.23.12
aks-nodepool1-21895026-vmss000001   Ready    agent   245s   v1.23.12
aks-userpool-21895026-vmss000000    Ready    agent   105s   v1.23.12
aks-userpool-21895026-vmss000001    Ready    agent   105s   v1.23.12