Update Kubernetes node labels and taints for node pools

This document provides instructions on how to update the Kubernetes node labels and node taints of an existing node pool in a Google Kubernetes Engine (GKE) Standard cluster by using the GKE API. Kubernetes node labels are distinct from GKE cluster and node labels.

Node taints and labels are in the object metadata of Kubernetes nodes. Kubernetes labels are used to schedule Pods on particular nodes. In contrast, taints can be used to steer Pods away from particular nodes. For more information, see Configure workload separation in GKE.

Using the GKE API, you can apply updates to the Kubernetes node labels and node taints of an existing GKE node pool without re-creating the node pool and disrupting running workloads. The updated node pool configuration is preserved in GKE, so that future node pool upgrades and new nodes provisioned in the node pool will use the new configuration.

For more information about how changes affect the operation of a GKE cluster, see Manage cluster lifecycle changes to minimize disruption. For details about specific changes, see the Types of changes to a GKE cluster section.

Label syntax

Kubernetes labels must meet all of the following requirements:

  • Label keys and values must meet the requirements for syntax and character set.
  • The length of the value that you specify in the --node-labels gcloud CLI flag must be less than or equal to 1,024 characters.

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
  • If you want 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.

Updating node labels

To update node labels for a node pool, use the following command:

gcloud container node-pools update NODEPOOL_NAME \
    --node-labels=[NODE_LABEL,...] \
    --cluster=CLUSTER_NAME
    --location=CONTROL_PLANE_LOCATION
    [GCLOUD_WIDE_FLAG ]

Replace the following:

  • NODEPOOL_NAME: the name of the node pool to update.
  • [NODE_LABEL,...]: the new node labels (for example, label1=value1,label2=value2).
  • CLUSTER_NAME: the name of the cluster.
  • CONTROL_PLANE_LOCATION: the Compute Engine location of the control plane of your cluster. Provide a region for regional clusters, or a zone for zonal clusters.

Updating node taints

To update node taints for a node pool, use the following command:

gcloud container node-pools update NODEPOOL_NAME \
    --node-taints=[NODE_TAINT,...] \
    --cluster=CLUSTER_NAME
    --location=CONTROL_PLANE_LOCATION
    [GCLOUD_WIDE_FLAG ]

Replace the following:

  • NODEPOOL_NAME: the name of the node pool to update.
  • [NODE_TAINT,...]: the new node taints (for example, key1=val1:NoSchedule,key2=val2:PreferNoSchedule).
  • CLUSTER_NAME: the name of the cluster.
  • CONTROL_PLANE_LOCATION: the Compute Engine location of the control plane of your cluster. Provide a region for regional clusters, or a zone for zonal clusters.