Resize a Standard cluster by adding or removing nodes

This document describes how to meet changes in compute demand by manually adding or removing nodes in your Google Kubernetes Engine (GKE) Standard cluster's node pools. These instructions don't apply to Autopilot clusters, which GKE scales automatically based on Pod resource requests. To adjust node counts automatically based on workload demand instead, see Autoscaling a cluster.

This document is for admins, architects, and operators who manually manage cluster capacity. For more information about common roles and example tasks that we reference in Google Cloud content, see Common GKE user roles and tasks.

How manual cluster resizing works

When you add or remove nodes in a node pool, GKE adds or removes virtual machine (VM) instances in the underlying Compute Engine managed instance groups (MIGs). To remove nodes, don't run the kubectl delete node command because that command doesn't delete the Compute Engine VM instance in the node pool's underlying MIG. Instead, use the cluster autoscaler or manually decrease the size of your cluster.

Before you begin

Before you start, make sure that you have performed the following tasks:

  • Enable the Google Kubernetes Engine API.
  • Enable Google Kubernetes Engine API
  • To use the Google Cloud CLI for this task, install and then initialize the gcloud CLI. If you previously installed the gcloud CLI, get the latest version by running the gcloud components update command. Earlier gcloud CLI versions might not support running the commands in this document.

Increase the size of your cluster

When you increase the size of a cluster, the following changes occur:

  • New node instances are created using the same configuration as the existing instances.
  • New Pods may be scheduled on the new instances.
  • Existing Pods are not moved to the new instances.

gcloud

To increase the size of a cluster's node pools, run the gcloud container clusters resize command:

gcloud container clusters resize CLUSTER_NAME --node-pool POOL_NAME \
    --num-nodes NUM_NODES

Replace the following:

  • CLUSTER_NAME: the name of the cluster to resize.
  • POOL_NAME: the name of the node pool to resize.
  • NUM_NODES: the number of nodes in the pool in a zonal cluster. If you use multi-zonal or regional clusters, NUM_NODES is the number of nodes for each zone the node pools is in.

Repeat this command for each node pool. If your cluster has only one node pool, omit the --node-pool flag.

Console

To increase the size of a cluster's node pools, perform the following steps:

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

    Go to Google Kubernetes Engine

  2. Beside the cluster you want to edit, click Actions, then click Edit.

  3. Click the Nodes tab next to the Details tab.

  4. In the Node Pools section, click the name of the node pool that you want to increase in size.

  5. Click Resize.

  6. In the Number of nodes field, enter how many nodes that you want in the node pool, and then click Resize.

  7. Repeat for each node pool as needed.

Decrease the size of your cluster

When you decrease the size of a cluster, the following changes occur:

  • GKE gracefully terminates nodes that are being deleted, using the drain process to remove the Pods from the instance. PodDisruptionBudget and terminationGracePeriodSeconds are both respected for up to one hour.
  • Pods managed by a replication controller are rescheduled by the controller to run on the remaining instances.
  • Pods not managed by a replication controller are not restarted.

The MIG does not differentiate between instances running Pods and instances without Pods. Resizing down removes instances at random.

To learn how to add node pools and to manage existing ones, refer to Adding and managing node pools.

gcloud

To decrease the size of a cluster's node pools, run the gcloud container clusters resize command:

gcloud container clusters resize CLUSTER_NAME --node-pool POOL_NAME \
    --num-nodes NUM_NODES

Replace the following:

  • CLUSTER_NAME: the name of the cluster to resize.
  • POOL_NAME: the name of the node pool to resize.
  • NUM_NODES: the number of nodes in the pool in a zonal cluster. If you use multi-zonal or regional clusters, NUM_NODES is the number of nodes for each zone the node pools is in.

Repeat this command for each node pool. If your cluster has only one node pool, omit the --node-pool flag.

Console

To decrease the size of a cluster's node pools, perform the following steps:

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

    Go to Google Kubernetes Engine

  2. Beside the cluster you want to edit, click Actions, then click Edit.

  3. Click the Nodes tab next to the Details tab.

  4. In the Node Pools section, click the name of the node pool that you want to decrease in size.

  5. Click Resize.

  6. In the Number of nodes field, enter how many nodes that you want in the node pool, and then click Resize.

  7. Repeat for each node pool as needed.

Autoscaling a cluster

GKE's cluster autoscaler feature automatically resizes your node pools in response to changing conditions, such as changes in your workloads and resource usage.

To learn more about how autoscaling works, refer to the cluster autoscaler documentation. To set up autoscaling for your cluster, see Autoscaling a cluster.

What's next