Cluster Autoscaler on AKS

Anoop L
2 min readFeb 6, 2019

--

Photo by Rebecca Georgia on Unsplash

Cluster Autoscaler is used to scale up or down cluster nodes according to load ( pending pods) or free nodes.

Earlier we had to manually configure Cluster Autoscaling on AKS cluster. Recently Azure AKS released this as a feature. So in this tutorial I would be explaining both the steps.

Manual:

  1. Generate the secret with the cluster details by running the following script:

https://gist.github.com/anoopl/d0bfb7c78a7a0027934689a7f675796d

2. Run the script and copy the output to a yaml file cluster-autoscaler.yaml:

3. Create the secret :

kubectl apply -f cluster-autoscaler-secret.yaml

4. Use the following yaml to create other resources for the CA:

You can set the minimum and maximum number of nodes in the yaml: — — nodes=1:10:nodepool1

Create the resources with : kubectl apply -f cluster-autoscaler-all.yaml

You can check the logs to see everything working as expected by checking CA Pod’s logs.

kubectl -n kube-system logs -f <cluster-autoscaler-pod>

Enable Cluster Autoscale feature on AKS

  1. Update the Az Cli to the latest version:

sudo apt-get update && sudo apt-get install --only-upgrade -y azure-cli

2. Enable aks preview mode

az extension add --name aks-preview

3. Create new cluster with Autoscaling enabled:

You can test the autoscaling by running a deployment of nginx with many replicaset:

Example:

https://gist.github.com/anoopl/891965dd6c9110cdc7950f2d1529041a

--

--