This project contains all steps in order to upgrade an existing AKS cluster, with az cli commands.
- Finding and defining variables
- Upgrade the control plane with the new version
- Add new node pools with new version
- Cordon and drain the old node pool
- Check the application is up and running
- Remove the old node pool
Finding and assigning to:
- cluster name
- resource group
- version of the K8s
az aks list -o table
export AKS_NAME="test-kube-cluster"
export AKS_RG="test"
export VERSION_OLD="1.21.7"
Finding the available version on your region.
az aks get-versions -l northeurope -o table
export VERSION_NEW="1.22.4"
Finding the properly VM size for the K8s cluster.
az vm list-sizes -l northeurope -o table
# 4vCPU 8GB RAM
export VM_SIZE_SYSTEM="Standard_D2s_v5"
# 16vCPU 64GB RAM
export VM_SIZE_USER="Standard_D8s_v3"
az aks upgrade --kubernetes-version $VERSION_NEW \
--control-plane-only \
--name $AKS_NAME \
--resource-group $AKS_RG
Add system node pool with taints to cluster.
# Creation/Add of system pool to cluster.
az aks nodepool add --name systempool \
--cluster-name $AKS_NAME \
--resource-group $AKS_RG \
--node-count 3 \
--node-vm-size $VM_SIZE_SYSTEM \
--kubernetes-version $VERSION_NEW \
--max-pods 30 \
--priority Regular \
--zones 1 2 3 \
--node-taints CriticalAddonsOnly=true:NoSchedule \
--mode System
Check that the new system node pool was added / created to the cluster.
az aks nodepool list --cluster-name $AKS_NAME --resource-group $AKS_RG -o table
az aks nodepool delete --cluster-name $AKS_NAME \
--name nodepool1 \
--resource-group $AKS_RG \
--no-wait
Add new user node pool with new K8s version.
az aks nodepool add \
--cluster-name $AKS_NAME \
--resource-group $AKS_RG \
--name apppool \
--node-count 3 \
--node-vm-size $VM_SIZE_USER \
--kubernetes-version $VERSION_NEW \
--max-pods 60 \
--zones 1 2 3 \
--priority Regular \
--mode User
Check that the new user node pool was added to the cluster.
az aks nodepool list --cluster-name $AKS_NAME --resource-group $AKS_RG -o table
Remove old system nodepool (if exists).
Cordon old user node pool.
kubectl cordon -l agentpool=oldpool
Drain old user node pool.
kubectl drain -l agentpool=oldpool --ignore-daemonsets --delete-emptydir-data
It should be defined for each namespace separately
Remove old user nodepool
az aks nodepool delete --cluster-name $AKS_NAME \
--name oldpool \
--resource-group $AKS_RG \
--no-wait
Check that the old user node pool was deleted from the cluster.
az aks nodepool list --cluster-name $AKS_NAME --resource-group $AKS_RG -o table