DEV Community

Cover image for How to apply Scale-down Mode to delete/deallocate nodes in AKS
MakendranG for Kubernetes Community Days Chennai

Posted on • Edited on

How to apply Scale-down Mode to delete/deallocate nodes in AKS

By default, scale-up operations performed manually or by using the cluster autoscaler require the allocation and provisioning of new nodes, and scale-down operations delete nodes. Scale-down Mode approves us to determine whether we would like to delete or deallocate the nodes in our Azure Kubernetes Service (AKS) cluster upon scaling down.

We won't be charged for the compute resources of the stopped virtual machine. We need to pay for the OS and data storage disks that are attached to the VM. The container images will be preserved on those nodes.

Our deployment uses cached images and this behavior allows for faster operation speeds. The scale-down mode eliminates the need for pre-provision and pre-pull images.

Before we start

We have an existing AKS cluster. If we need an AKS cluster, see the AKS quick start using the Azure CLI, using Azure PowerShell, or using the Azure portal.

Using Scale-down Mode to deallocate nodes

By setting --scale-down-mode deallocate, we will be able to deallocate during a scale-down of our pool. The deallocated nodes are stopped. When the pool needs to scale up, the deallocated nodes will be the first to be started.

In this example, we create a new pool with 20 nodes and specify that upon scale-down, they will be dealt with via --scale-down-mode Deallocate.

az aks nodepool add --node-count 20 --scale-down-mode Deallocate --node-osdisk-type Managed --max-pods 10 --name kcdpool1 --cluster-name kcdAKSCluster --resource-group kcdrg
Enter fullscreen mode Exit fullscreen mode

We will deallocate 15 nodes by scaling the pool and changing the count to 5.

az aks nodepool scale --node-count 5 --name kcdpool1 --cluster-name kcdAKSCluster --resource-group kcdrg
Enter fullscreen mode Exit fullscreen mode

Deleting formerly deallocated nodes

The Scale-down Mode to Delete can be changed by setting it. The 15 nodes will be deleted.

az aks nodepool update --scale-down-mode Delete --name kcdpool1 --cluster-name kcdAKSCluster --resource-group kcdrg
Enter fullscreen mode Exit fullscreen mode

Using Scale-down Mode to remove nodes

When you scale-down your cluster, the default behavior of AKS is to remove your nodes. This behavior can be achieved by setting Scale-down Mode.

In this example, we create a new pool and specify that our nodes will be deleted upon scale-down. The cluster autoscaler will handle scaling operations.

az aks nodepool add --enable-cluster-autoscaler --min-count 1 --max-count 10 --max-pods 10 --node-osdisk-type Managed --scale-down-mode Delete --name kcdpool3 --cluster-name kcdAKSCluster --resource-group kcdrg
Enter fullscreen mode Exit fullscreen mode

Thanks for reading my article till end. I hope you learned something special today. If you enjoyed this article then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box.

Top comments (0)