How to Enable the Cluster Autoscaler for a DigitalOcean Kubernetes Cluster

DigitalOcean Kubernetes provides a Cluster Autoscaler (CA) that automatically adjusts the size of a Kubernetes cluster by adding or removing nodes based on the cluster’s capacity to schedule pods.

You can enable autoscaling with minimum and maximum cluster sizes using either the DigitalOcean Control Panel or doctl, the DigitalOcean command-line tool.

Enable Autoscaling

Using the DigitalOcean Control Panel

To enable autoscaling on an existing node pool, navigate to your cluster in the Kubernetes section of the control panel, then click on the Nodes tab. Click on the three dots to reveal the option to resize the node pool manually or enable autoscaling.

DOKS node pool screen

Select Resize or Autoscale, and a modal window will pop up asking for configuration details. After selecting Autoscale, you can set the following options for the node pool:

  • Minimum Nodes: Determines the smallest size the cluster will be allowed to “scale down” to; must be no less than 1 and no greater than Maximum Nodes.
  • Maximum Nodes: Determines the largest size the cluster will be allowed to “scale up” to. The upper limit is constrained by the Droplet limit on your account, which is 25 by default, and the number of Droplets already running, which subtracts from that limit. You can request to have your Droplet limit increased.
DOKS node pool resizing modal

Using doctl

You can use doctl to enable cluster autoscaling on any node pool. You’ll need to provide three specific configuration values:

  • auto-scale: Specifies that autoscaling should be enabled
  • min-nodes: Determines the smallest size the cluster will be allowed to “scale down” to; must be no less than 1 and no greater than max-nodes
  • max-nodes: Determines the largest size the cluster will be allowed to “scale up” to. The upper limit is constrained by the Droplet limit on your account, which is 25 by default, and the number of Droplets already running, which subtracts from that limit. You can request to have your Droplet limit increased.

You can apply autoscaling to a node pool at cluster creation time if you use a semicolon-delimited string.

doctl kubernetes cluster create mycluster --node-pool "name=mypool;auto-scale=true;min-nodes=1;max-nodes=10"

You can also configure new node pools to have autoscaling enabled at creation time.

doctl kubernetes cluster node-pool create mycluster mypool --auto-scale --min-nodes 1 --max-nodes 10

If your cluster is already running, you can enable autoscaling on an any existing node pool.

doctl kubernetes cluster node-pool update mycluster mypool --auto-scale --min-nodes 1 --max-nodes 10

Disabling Autoscaling

Using the DigitalOcean Control Panel

To disable autoscaling on an existing node pool, navigate to your cluster in the Kubernetes section of the control panel, then click on the Nodes tab. Click on the three dots to reveal the option to resize the node pool manually or enable autoscaling.

DOKS node pool screen

Select Resize or Autoscale, and a modal window will pop up asking for configuration details. Select Fixed size and configure the number of nodes you want to assign to the pool.

DOKS node pool configuration modal

Using doctl

To disable autoscaling, run an update command that specifies the node pool and cluster:

doctl kubernetes cluster node-pool update mycluster mypool --auto-scale=false

Autoscaling in Response to Heavy Resource Use

Pod creation and destruction can be automated by a Horizonal Pod Autoscaler (HPA), which monitors the resource use of nodes and generates pods when certain events occur, such as sustained CPU spikes, or memory use surpassing a certain threshold. This, combined with a CA, gives you powerful tools to configure your cluster’s responsiveness to resource demands — an HPA that ensures synchronicity between resource use and the number of pods, and a CA that ensures synchronicity between the number of pods and the cluster’s size.

For a walkthrough that builds an autoscaling cluster and demonstrates the interplay between an HPA and a CA, see Example of Kubernetes Cluster Autoscaling Working With Horizontal Pod Autoscaling.

PodDisruptionBudget support

A PodDisruptionBudget (PDB) specifies the minimum number of replicas that an application can tolerate having during a voluntary disruption, relative to how many it is intended to have. For example, if you set the replicas value for a pod to 5, and set the PDB to 1, potentially disruptive actions like cluster upgrades and resizes will occur with no fewer than four pods running.

When scaling down a cluster, the DOKS autoscaler respects this setting, and will follow the documented Kubernetes procedure for draining and deleting nodes when a PDB has been specified.

We recommend you set a PDB for your workloads to ensure graceful scaledown. For more information, see Specifying a Disruption Budget for your Application in the Kubernetes documentation.