Scale the nodes and upgrade the cluster
In this task you'll scale an AKS node pool.
There are two kinds of scaling in AKS. You can run more pods of an app, which uses spare room on the nodes you have, or more nodes, which adds VMs to the cluster. The cluster autoscaler adds and removes nodes by itself when pods can't fit or nodes sit empty.
Kubernetes versions are only supported for about a year, so clusters also need regular upgrades. AKS upgrades the control plane first, then replaces nodes one at a time so apps keep running.
Example. Larkfield Group's cluster autoscaler runs between two and six nodes. On payroll day the extra jobs push it to five nodes, and by the evening it has shrunk back to two.
Costs money. More nodes means more VMs to pay for. Scaling to two small nodes for a few minutes costs a few pence. Scale back, and delete the cluster when you've finished this section.
Before you start
You need: Contributor on the cluster. Time: 15 minutes.
Where to look
- Kubernetes services
- aks-practice
- Node pools
Steps
- Scale the app first: in Cloud Shell run
kubectl scale deployment hello --replicas=3, thenkubectl get podsto see three pods.This uses spare room on the existing node, so it costs nothing extra. - In the portal, open aks-practice and select Node pools, then the pool's name.
- Select ... and then Scale node pool. Choose Manual, set the Node count to 2 and select Apply.A second VM is created and joins the cluster in a few minutes.
- Check it with
kubectl get nodes, then scale back to 1 the same way. - To see the autoscaler option, open Scale node pool again and look at Autoscale with a minimum and maximum. Cancel without saving.
- Select Upgrades (under Settings) and look at the Kubernetes version, the automatic upgrade setting and Upgrade version. Don't upgrade a practice cluster unless you want to watch it.Upgrades replace each node, so they take a while and briefly need room for an extra node.
Tip. Node pools and Upgrades are under Settings in the cluster's left menu.
Commands
# More pods of the app
kubectl scale deployment hello --replicas=3
# More nodes (the CLI's default pool is called nodepool1; the portal's is agentpool)
az aks scale --resource-group rg-portal-practice --name aks-practice \
--node-count 2 --nodepool-name agentpool
# Let AKS scale between 1 and 3 nodes by itself
az aks nodepool update --resource-group rg-portal-practice --cluster-name aks-practice \
--name agentpool --enable-cluster-autoscaler --min-count 1 --max-count 3
# Which versions can this cluster upgrade to?
az aks get-upgrades --resource-group rg-portal-practice --name aks-practice --output table
Watch out for
- Cost
- Every extra node is another VM on the bill. Set a sensible maximum on the autoscaler, so a runaway app can't add dozens of nodes.
- Security
- Out-of-date clusters stop getting security fixes. Plan upgrades regularly and turn on automatic node image upgrades for real clusters.
- Common mistakes
- Scaling pods beyond what the nodes can hold without an autoscaler, which leaves pods stuck as Pending. Skipping several Kubernetes versions: you can only upgrade one minor version at a time.
Clean up
- Resource groups
- rg-portal-practice
- Delete resource group
You've finished the AKS section: delete the resource group straight away. It removes the cluster, and AKS removes its MC_ node resource group too. Check both have gone.
Words to know
- Cluster autoscaler
- An AKS feature that adds or removes nodes based on what the pods need.
- Replicas
- The number of copies (pods) of an app that Kubernetes keeps running.
- Node image upgrade
- Updating the operating system on the nodes, separate from upgrading Kubernetes itself.
Tick off each step and track your progress in the guide.
Open this task in Azure Portal, Hands On