GKE - Google Kubernetes Engine

GKE Deployment and Administration

Demo Apply labels and tags to GKE clusters

In this tutorial, you’ll learn how to manage labels on Google Kubernetes Engine (GKE) clusters and their node pools. You will:

  1. Create a new GKE cluster with labels
  2. View labels on an existing cluster
  3. Update labels on a cluster
  4. Remove labels from a cluster
  5. Verify labels on both the cluster and its node pools
  6. Understand how cluster-level label changes affect node pools

Table of Contents


1. Create a New Cluster with a Label

Spin up a GKE cluster named gke-deep-dive-new with:

  • 1 node
  • 10 GB standard persistent disk
  • Label test=gke
gcloud container clusters create gke-deep-dive-new \
  --num-nodes=1 \
  --disk-type=pd-standard \
  --disk-size=10 \
  --labels=test=gke

This command provisions a single-node pool (HDD) and attaches the test=gke label at creation.


2. View Labels on an Existing Cluster

To inspect labels on a cluster (e.g., gke-deep-dive) run:

gcloud container clusters describe gke-deep-dive \
  --format="yaml(resourceLabels)"

If there are no labels, the resourceLabels section will be empty.


3. Update Labels on an Existing Cluster

Add or modify labels using --update-labels. For example, set newlabel=gkeold on gke-deep-dive:

gcloud container clusters update gke-deep-dive \
  --update-labels=newlabel=gkeold

Verify the update:

gcloud container clusters describe gke-deep-dive \
  --format="yaml(resourceLabels)"

Expected output:

resourceLabels:
  newlabel: gkeold

4. Remove a Label from a Cluster

To delete a label, specify its key with --remove-labels:

gcloud container clusters update gke-deep-dive \
  --remove-labels=newlabel

Confirm removal:

gcloud container clusters describe gke-deep-dive \
  --format="yaml(resourceLabels)"

The resourceLabels field should now be empty.


5. Verify Labels on the New Cluster

Check that gke-deep-dive-new has the test=gke label:

gcloud container clusters describe gke-deep-dive-new \
  --format="yaml(resourceLabels)"

You should see:

resourceLabels:
  test: gke

Alternatively, filter with grep:

gcloud container clusters describe gke-deep-dive-new \
  | grep -i resourceLabels -A1

6. Remove the Label from the New Cluster

Remove the test label:

gcloud container clusters update gke-deep-dive-new \
  --remove-labels=test

Verify:

gcloud container clusters describe gke-deep-dive-new \
  --format="yaml(resourceLabels)"

resourceLabels will now be empty.


7. Node Pool Labels Remain After Cluster Label Removal

Cluster-level label updates do not automatically propagate to existing node pools. Even after removing test from the cluster, the default node pool still holds its label:

gcloud container clusters describe gke-deep-dive-new \
  --format="yaml(nodePools[0].resourceLabels)"
resourceLabels:
  test: gke

To remove a label from the node pool itself:

gcloud container node-pools update default-pool \
  --cluster=gke-deep-dive-new \
  --remove-labels=test

Note

After detaching a label from the cluster, always verify node-pool labels if you rely on them for workloads, autoscaling, or monitoring.


Command Reference

OperationCommand Snippet
Create cluster with labelgcloud container clusters create ... --labels=test=gke
View cluster labelsgcloud container clusters describe ... --format="yaml(...)"
Update cluster labelsgcloud container clusters update ... --update-labels=key=val
Remove cluster labelsgcloud container clusters update ... --remove-labels=key
View node-pool labelsgcloud container clusters describe ... --format="yaml(...)"
Remove node-pool labelgcloud container node-pools update ... --remove-labels=key

Watch Video

Watch video content

Previous
Demo Install kubectl and configure cluster access