How to update a Kubernetes cluster

How to update a Kubernetes cluster

I have logged some time ago How I have moved my Ghost blog to Azure Kubernetes.

The point is that periodically Kubernetes gets updated and as described in Upgrade an Azure Kubernetes Service (AKS) cluster:

As part of the lifecycle of an AKS cluster, you often need to upgrade to the latest Kubernetes version. It is important you apply the latest Kubernetes security releases, or upgrade to get the latest features.

So from my Azure CLI I have run the following command:

damiano@Azure:~$ az aks get-upgrades --resource-group RG_CuriaKube --name CuriaKube --output table

that shows me the following table:

Name     ResourceGroup    MasterVersion    Upgrades
-------  ---------------  ---------------  ----------
default  RG_CuriaKube     1.15.10          1.16.7

This shows that there are updates available!

There is the possibility that Azure automatically configures monitoring, that prevents the next upgrade. Disable it with:

az aks disable-addons --addons monitoring --resource-group RG_CuriaKube --name CuriaKube

Then I have proceeded with the upgrade:

damiano@Azure:~$ az aks upgrade --resource-group RG_CuriaKube --name CuriaKube --kubernetes-version 1.16.7
Kubernetes may be unavailable during cluster upgrades.
Are you sure you want to perform this operation? (y/n): y
Since control-plane-only argument is not specified, this will upgrade the control plane AND all nodepools to version 1.16.7. Continue? (y/N): y

This will output a very big json file, containing also some sensitive information like subscriptions and RSA keys, so I won't copy it here.
But hopefully it starts with:

{- Finished ..

Finally you will want to verify the success of the upgrade:

damiano@Azure:~$ az aks show --resource-group RG_CuriaKube --name CuriaKube --output table

and get something like:

Name       Location    ResourceGroup    KubernetesVersion    ProvisioningState    Fqdn
---------  ----------  ---------------  -------------------  -------------------  --------------------------------------------------------------
CuriaKube  westeurope  RG_CuriaKube     1.16.7               Succeeded  

This was the quick way.
How to update in a safe way - credit to Andre /abossard/:

  • get nodepool:
    az aks nodepool list --resource-group RG_CuriaKube --cluster-name CuriaKube --output table
  • create a new nodepool (from
    something like
    az aks nodepool add --resource-group myResourceGroup --cluster-name myAKSCluster --name mynodepool --node-count 3
  • scale the old nodepool to zero
  • wait that the deploy has been moved to the new nodepool
    how to run kubectl from the cloud shell?!?
  • test the app
  • if it doesnt work, scale back the old nodepool and scale the new nodepool to zero
  • if it works, delete the old nodepool