Andrew Mercer
on this page
  • https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli

Prerequisites

az login
az account set --subscription <subscription-id>
az provider register --namespace Microsoft.ContainerService

Variables

RG=rg-aks-lab
CLUSTER=aks-lab
LOCATION=canadacentral

See which Kubernetes versions are available in the region:

az aks get-versions --location $LOCATION -o table

Create the cluster

az group create --name $RG --location $LOCATION

az aks create \
  --resource-group $RG \
  --name $CLUSTER \
  --node-count 2 \
  --node-vm-size Standard_D2s_v5 \
  --network-plugin azure \
  --network-plugin-mode overlay \
  --generate-ssh-keys
  • --network-plugin azure --network-plugin-mode overlay (Azure CNI Overlay) gives pods IPs from a private overlay CIDR rather than consuming VNet addresses.
  • AKS uses a system-assigned managed identity by default.
  • Add --kubernetes-version <x.y.z> to pin a version, and --enable-cluster-autoscaler --min-count 1 --max-count 3 for autoscaling.

Connect

az aks get-credentials --resource-group $RG --name $CLUSTER
kubectl get nodes

This merges the cluster into ~/.kube/config and switches context. See merging kubeconfig files for managing several clusters.

Clean up

Deleting the resource group removes the cluster. AKS also deletes the MC_* node resource group it created:

az group delete --name $RG --yes --no-wait