Managing clusters

This page shows you how to manage your clusters in Google Kubernetes Engine (GKE). To learn about how clusters work, refer to Cluster architecture.

Before you begin

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

Set up default gcloud settings using one of the following methods:

  • Using gcloud init, if you want to be walked through setting defaults.
  • Using gcloud config, to individually set your project ID, zone, and region.

Using gcloud init

If you receive the error One of [--zone, --region] must be supplied: Please specify location, complete this section.

  1. Run gcloud init and follow the directions:

    gcloud init

    If you are using SSH on a remote server, use the --console-only flag to prevent the command from launching a browser:

    gcloud init --console-only
  2. Follow the instructions to authorize gcloud to use your Google Cloud account.
  3. Create a new configuration or select an existing one.
  4. Choose a Google Cloud project.
  5. 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
  • Update gcloud to the latest version:
    gcloud components update

Viewing your clusters

gcloud

To view a specific cluster, run the following command:

gcloud container clusters describe cluster-name

To view all clusters in your default zone:

gcloud container clusters list

Console

To view your clusters, visit the Google Kubernetes Engine menu in Cloud Console.

Visit the Google Kubernetes Engine menu

To see more information about a cluster, select the cluster from the list.

Setting a default cluster for kubectl

If you have multiple clusters, you can set a default cluster for the kubectl command-line tool.

To learn more, refer to Setting a default cluster for kubectl commands.

Setting a default cluster for gcloud

gcloud

To set a default cluster for gcloud commands, run the following command:

gcloud config set container/cluster cluster-name

Upgrading clusters

By default, GKE automatically upgrades your clusters. However, you can choose to upgrade them yourself. To learn more, see Manually upgrading a cluster.

For guidance on upgrading clusters, see Best practices for upgrading clusters.

Adding or removing zones

The following sections explain how to add or remove cluster zones.

Changing zones for zonal clusters

gcloud

To add or remove zones for a zonal cluster, use the gcloud container clusters update command:

gcloud container clusters update cluster-name \
  --zone compute-zone \
  --node-locations [compute-zone,compute-zone,...]

where:

  • cluster-name is the name you choose for the cluster
  • compute-zone is the zone for the cluster control plane
  • [compute-zone, compute-zone...] is all of the desired zones. Include the cluster control plane's zone.

For example, example-cluster runs in us-central1-a. To add two more zones to the cluster, you'd run the following command:

gcloud container clusters update example-cluster \
  --zone us-central1-a
  --node-locations us-central1-a,us-central1-b,us-central1-c

As another example, example-cluster runs in us-central1-a, us-central1-b and us-central1-c. If you only want the cluster to run in us-central1-a and us-central1-b, you'd run the following command:

gcloud container clusters update example-cluster \
  --zone us-central1-a \
  --node-locations us-central1-a,us-central1-b

Console

To add or remove zones in an existing cluster, perform the following steps:

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

    Visit the Google Kubernetes Engine menu

  2. Click the cluster's Edit button, which looks like a pencil.

  3. From the Additional zones section, select the desired zones.

  4. Click Save.

Changing zones for regional clusters

Currently, it is only possible to change the zones for existing regional clusters using the gcloud command.

gcloud

To add or remove zones for a regional cluster, use the gcloud container clusters update command with the --region flag:

gcloud container clusters update cluster-name \
  --region region \
  --node-locations [compute-zone,compute-zone,...]

where:

  • cluster-name is the name of the cluster.
  • region is the region in which the cluster runs.
  • [compute-zone,compute-zone,...] is all of the desired zones.

For example, example-cluster runs in us-central1-a and us-central1-b. To add us-central1-c, you'd run the following command:

gcloud container clusters update example-cluster \
  --region us-central1 \
  --node-locations us-central1-a,us-central1-b,us-central1-c

As another example, example-cluster runs in us-central1-a, us-central1-b and us-central1-c. If you only want the cluster to run in us-central1-a and us-central1-b, you'd run the following command:

gcloud container clusters update example-cluster \
  --region us-central1 \
  --node-locations us-central1-a,us-central1-b

Resizing clusters

You can resize a cluster to increase or decrease the number of nodes it has. For example, if you want to stop your cluster from consuming resources without deleting it, you can scale the nodes down to zero. To learn more about resizing, see Resizing a cluster.

If you would like a more efficient way to optimize your clusters, you can also use Vertical Pod Autoscaling (VPA). The autoscaler can recommend values for CPU and memory requests and limits, or it can automatically update the values.

Deleting clusters

When needed, you can delete a cluster. To learn more, see Deleting a cluster.

What's next