Autoscaling a cluster


This page shows you how to autoscale your Standard Google Kubernetes Engine (GKE) clusters. To learn about how the cluster autoscaler works, refer to Cluster autoscaler.

With Autopilot clusters, you don't need to worry about provisioning nodes or managing node pools because node pools are automatically provisioned through node auto-provisioning, and are automatically scaled to meet the requirements of your workloads.

Using cluster autoscaler

The following sections explain how to use cluster autoscaler.

Creating a cluster with autoscaling

gcloud

To create a cluster with autoscaling enabled, use the --enable-autoscaling flag and specify --min-nodes and --max-nodes as in the following command:

gcloud container clusters create CLUSTER_NAME \
    --enable-autoscaling \
    --num-nodes NUM_NODES \
    --min-nodes MIN_NODES \
    --max-nodes MAX_NODES \
   [--region COMPUTE_REGION | --zone COMPUTE_ZONE]

Replace the following:

  • CLUSTER_NAME: the name of the cluster to create.
  • NUM_NODES: the number of nodes to create in each location.
  • MIN_NODES: the minimum number of nodes to automatically scale for the specified node pool.
  • MAX_NODES: the maximum number of nodes to automatically scale for the specified node pool.
  • COMPUTE_REGION: if you are creating a regional cluster, specify the region in which to create the cluster.
  • COMPUTE_ZONE: if you are creating a zonal cluster, specify the zone in which to create the cluster.

Example: Creating a cluster with node autoscaling enabled

The following command creates a cluster with 30 nodes. Node autoscaling is enabled and resizes the number of nodes based on cluster load. The cluster autoscaler can reduce the size of the default node pool to 15 nodes or increase the node pool to a maximum of 50 nodes.

gcloud container clusters create my-cluster --enable-autoscaling \
    --num-nodes 30 \
    --min-nodes 15 --max-nodes 50 \
    --zone us-central1-c

Console

To create a new cluster in which the default node pool has autoscaling enabled:

  1. Go to the Google Kubernetes Engine page in Cloud Console.

    Go to Google Kubernetes Engine

  2. Click Create.

  3. Configure your cluster as desired.

  4. From the navigation pane, under Node Pools, click default-pool.

  5. Select the Enable autoscaling checkbox.

  6. Change the values of the Minimum number of nodes and Maximum number of nodes fields as desired.

  7. Click Create.

Adding a node pool with autoscaling

gcloud

To add a node pool with autoscaling to an existing cluster, use the following command:

gcloud container node-pools create POOL_NAME \
    --cluster CLUSTER_NAME \
    --enable-autoscaling \
    --min-nodes MIN_NODES \
    --max-nodes MAX_NODES \
    --zone COMPUTE_ZONE

Replace the following:

  • POOL_NAME: the name of the desired node pool.
  • CLUSTER_NAME: the name of the cluster in which the node pool is created.
  • MIN_NODES: the minimum number of nodes to automatically scale for the specified node pool.
  • MAX_NODES: the maximum number of nodes to automatically scale for the specified node pool.
  • COMPUTE_ZONE: the zone in which the autoscaler should create new nodes.

Example: Adding a node pool with node autoscaling enabled

The following command creates a node pool named of size 3 (default), with node autoscaling based on cluster load that scales the node pool to a maximum of 5 nodes and a minimum of 1 node:

gcloud container node-pools create my-node-pool \
    --cluster my-cluster \
    --enable-autoscaling \
    --min-nodes 1 --max-nodes 5 \
    --zone us-central1-c

Console

To add a node pool with autoscaling to an existing cluster:

  1. Visit the Google Kubernetes Engine menu in Cloud Console.

    Visit the Google Kubernetes Engine menu

  2. In the cluster list, click the name of the cluster you want to modify.

  3. Click Add Node Pool.

  4. Configure the node pool as desired.

  5. Under Size, select the Enable autoscaling checkbox.

  6. Change the values of the Minimum number of nodes and Maximum number of nodes fields as desired.

  7. Click Create.

Enabling autoscaling for an existing node pool

gcloud

To enable autoscaling for an existing node pool use the --enable-autoscaling flag as in the following command:

gcloud container clusters update CLUSTER_NAME \
    --enable-autoscaling \
    --node-pool POOL_NAME \
    --min-nodes MIN_NODES \
    --max-nodes MAX_NODES \
    [--region COMPUTE_REGION | --zone COMPUTE_ZONE]

Replace the following:

  • CLUSTER_NAME: the name of the cluster to update.
  • POOL_NAME: the name of the desired node pool. If you have only one node pool, supply default-pool as the value.
  • MIN_NODES: the minimum number of nodes to automatically scale for the specified node pool.
  • MAX_NODES: the maximum number of nodes to automatically scale for the specified node pool.
  • COMPUTE_REGION: for regional clusters, specify the region of the cluster.
  • COMPUTE_ZONE: for zonal clusters, specify the zone of the cluster.

Console

To enable autoscaling for an existing node pool:

  1. Visit the Google Kubernetes Engine menu in Cloud Console.

    Visit the Google Kubernetes Engine menu

  2. In the cluster list, click the name of the cluster you want to modify.

  3. Click the Nodes tab.

  4. Under Node Pools, click the name of the node pool you want to modify, then click Edit.

  5. Under Size, select the Enable autoscaling checkbox.

  6. Change the values of the Minimum number of nodes and Maximum number of nodes fields as desired.

  7. Click Save.

Disabling autoscaling for an existing node pool

gcloud

To disable autoscaling for a specific node pool, use the --no-enable-autoscaling flag as in the following command:

gcloud container clusters update CLUSTER_NAME \
    --no-enable-autoscaling \
    --node-pool POOL_NAME \
   [--region COMPUTE_REGION | --zone COMPUTE_ZONE]

Replace the following:

  • CLUSTER_NAME: the name of the cluster to update.
  • POOL_NAME: the name of the desired node pool.
  • COMPUTE_REGION: for regional clusters, specify the region of the cluster.
  • COMPUTE_ZONE: for zonal clusters, specify the zone of the cluster.

The cluster size is fixed at the cluster's current default node pool size, which can be manually updated.

Console

To disable autoscaling for a specific node pool:

  1. Visit the Google Kubernetes Engine menu in Cloud Console.

    Visit the Google Kubernetes Engine menu

  2. In the cluster list, click the name of the cluster you want to modify.

  3. Click the Nodes tab.

  4. Under Node Pools, click the name of the node pool you want to modify, then click Edit.

  5. Under Size, clear the Enable autoscaling checkbox.

  6. Click Save.

Resizing a node pool

For clusters with autoscaling enabled, the cluster autoscaler automatically resizes node pools within the boundaries specified by the minimum size (--min-nodes) and maximum size (--max-nodes) values. You cannot manually resize a node pool by changing these values.

If you want to manually resize a node pool in your cluster that has autoscaling enabled, perform the following:

  1. Disable autoscaling on the node pool.
  2. Manually resize the cluster.
  3. Re-enable autoscaling and specify the minimum and maximum node pool size.

Troubleshooting

See the following troubleshooting information for cluster autoscaler:

  • You might be experiencing one of the limitations for cluster autoscaler.
  • If you are having problems with downscaling your cluster, see Pod scheduling and disruption. You might have to add a PodDisruptionBudget for the kube-system Pods. For more information about manually adding a PodDisruptionBudget for the kube-system Pods, see the Kubernetes cluster autoscaler FAQ.
  • When scaling down, cluster autoscaler respects scheduling and eviction rules set on Pods. These restrictions can prevent a node from being deleted by the autoscaler. A node's deletion could be prevented if it contains a Pod with any of these conditions:
    • The Pod's affinity or anti-affinity rules prevent rescheduling.
    • The Pod has local storage.
    • The Pod is not managed by a Controller such as a Deployment, StatefulSet, Job or ReplicaSet.

For more information about cluster autoscaler and preventing disruptions, see the following questions in the Kubernetes cluster autoscaler FAQ:

What's next