Cluster Autoscaler on AKS

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

  1. Run the script and copy the output to a yaml file cluster-autoscaler.yaml:
  1. Create the secret :

    kubectl apply -f cluster-autoscaler-secret.yaml
    
  2. 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 : ```console kubectl apply -f cluster-autoscaler-all.yaml ``` You can check the logs to see everything working as expected by checking CA Pod’s logs. > ```console kubectl -n kube-system logs -f ``` Enable Cluster Autoscale feature on AKS 1. Update the Az Cli to the latest version: ```console sudo apt-get update && sudo apt-get install --only-upgrade -y azure-cli ``` 2. Enable aks preview mode ```console 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