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:

  • 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 command-line tool settings for your project by using one of the following methods:
    • Use gcloud init, if you want to be walked through setting project defaults.
    • Use gcloud config, to individually set your project ID, zone, and region.

    gcloud init

    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 the gcloud tool 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.
    6. Choose a default Compute Engine region.

    gcloud config

    1. Set your default project ID:
      gcloud config set project PROJECT_ID
    2. Set your default Compute Engine region (for example, us-central1):
      gcloud config set compute/region COMPUTE_REGION
    3. Set your default Compute Engine zone (for example, us-central1-c):
      gcloud config set compute/zone COMPUTE_ZONE
    4. Update gcloud to the latest version:
      gcloud components update

    By setting default locations, you can avoid errors in gcloud tool like the following: One of [--zone, --region] must be supplied: Please specify location.

Viewing your clusters

gcloud

To view a specific cluster, run the following command:

gcloud container clusters describe CLUSTER_NAME

Replace CLUSTER_NAME with the name of your cluster.

To view all clusters in your default zone:

gcloud container clusters list

Console

To view your clusters, go to the Google Kubernetes Engine page in Cloud Console.

Go to Google Kubernetes Engine

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

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

gcloud config set container/cluster CLUSTER_NAME

Replace CLUSTER_NAME with the name of your cluster.

Upgrading clusters

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

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

Adding or removing zones

This section applies only to clusters created in the Standard mode.

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

Changing zones for zonal clusters

For existing zonal clusters, you can add or remove zones.

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_ZONE1

Replace the following:

  • CLUSTER_NAME: the name you choose for the cluster.
  • COMPUTE_ZONE: the zone for the cluster control plane.
  • COMPUTE_ZONE,COMPUTE_ZONE1,[...]: the zones in which nodes are created. You can specify as many zones as needed for your cluster. All zones must be in the same region as the cluster's control plane, specified by the --zone flag. For zonal clusters, --node-locations must contain the cluster's primary 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. Go to the Google Kubernetes Engine page in Cloud Console.

    Go to Google Kubernetes Engine

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

  3. Under the Details tab, for the Default node zones field, click Edit node pools.

  4. Select the desired zones and save your changes.

Changing zones for regional clusters

This section applies only to clusters created in the Standard mode.

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

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 COMPUTE_REGION \
  --node-locations COMPUTE_ZONE,COMPUTE_ZONE1

Replace the following:

  • CLUSTER_NAME: the name of the cluster.
  • COMPUTE_REGION: the region in which the cluster runs.
  • COMPUTE_ZONE,COMPUTE_ZONE1,[...]: the zones control plane region in which the nodes are created. The zones must be in the same COMPUTE_REGION as the cluster's control plane(s), specified by the --region flag.

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 Standard 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.

Autopilot clusters are sized automatically based on your Pod specifications, so resizing your cluster isn't something you need to worry about. For example, if you change the number of replicas of your Pod, or the resources it requests, the cluster will be sized up or down appropriately.

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