This page explains how to resize clusters. You can resize a cluster to increase or decrease the number of nodes in that cluster. To learn how to add node pools and manage your existing node pools, refer to Adding and Managing Node Pools.
Before you begin
Before you start, make sure you have performed the following tasks:
- Ensure that you have enabled the Google Kubernetes Engine API. Enable Google Kubernetes Engine API
- Ensure that you have installed the Cloud SDK.
Set up default
gcloud settings using one of the following methods:
gcloud init, if you want to be walked through setting defaults.
gcloud config, to individually set your project ID, zone, and region.
Using gcloud init
gcloud initand follow the directions:
If you are using SSH on a remote server, use the
--console-onlyflag to prevent the command from launching a browser:
gcloud init --console-only
Follow the instructions to authorize
gcloudto use your Google Cloud account.
- Create a new configuration or select an existing one.
- Choose a Google Cloud project.
- Choose a default Compute Engine zone.
Using gcloud config
- Set your default project ID:
gcloud config set project [PROJECT_ID]
- If you are working with zonal clusters, set your default compute zone:
gcloud config set compute/zone [COMPUTE_ZONE]
- If you are working with regional clusters, set your default compute region:
gcloud config set compute/region [COMPUTE_REGION]
gcloudto the latest version:
gcloud components update
Resizing a cluster
To resize a cluster's node pools, run the following command:
gcloud container clusters resize [CLUSTER_NAME] --node-pool [POOL_NAME] \ --num-nodes [NUM_NODES]
- [CLUSTER_NAME] is the cluster's name.
- [POOL_NAME] is the name of the node pool to resize.
- [NUM_NODES] is 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
For more information, refer to the
gcloud container clusters resize
To resize a cluster's node pools, perform the following steps:
Visit the Google Kubernetes Engine menu in Cloud Console.
Click the cluster's Edit button, which looks like a pencil.
In the Node pools section, expand the disclosure arrow for the node pool you want to change, and change the value of the Current size field to the desired value, then click Save.
Repeat for each node pool as needed.
Click Save to exit the cluster modification screen.
Increasing the size of your cluster
When you increase the size of a cluster:
- New node instances are created using the same configuration as the existing instances
- New Pods may be scheduled onto the new instances
- Existing Pods are not moved onto the new instances
When you increase the size of a node pool that spans multiple zones, the new size represents the number of nodes in the node pool per zone. For example, if you have a node pool of size 2 spanning two zones, the total node count is 4. If you resize the node pool to size 4, the total node count becomes 8.
Decreasing the size of your cluster
When you decrease the size of a cluster:
- The Pods that are scheduled on the instances being removed are killed
- Pods managed by a replication controller are rescheduled by the controller onto the remaining instances
- Pods not managed by a replication controller are not restarted
The managed instance group does not differentiate between instances running Pods and instances without Pods. Resizing down removes instances at random.
Decreasing the size of your cluster with drain
You can manually decrease the size of your cluster and have such instance's Pods be drained before they are removed.
To learn how to add node pools and to manage existing ones, refer to Adding and Managing Node Pools.
To decrease and drain your cluster, run the following command:
gcloud beta container clusters resize [CLUSTER_NAME] --node-pool [NODE_POOL] \ --num-nodes [NUM_NODES]
For a description of the command line options, see Resizing a cluster.
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.