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:
- Create a new GKE cluster with labels
- View labels on an existing cluster
- Update labels on a cluster
- Remove labels from a cluster
- Verify labels on both the cluster and its node pools
- Understand how cluster-level label changes affect node pools
Table of Contents
- 1. Create a New Cluster with a Label
- 2. View Labels on an Existing Cluster
- 3. Update Labels on an Existing Cluster
- 4. Remove a Label from a Cluster
- 5. Verify Labels on the New Cluster
- 6. Remove the Label from the New Cluster
- 7. Node Pool Labels Remain After Cluster Label Removal
- Command Reference
- Links and References
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
| Operation | Command Snippet |
|---|---|
| Create cluster with label | gcloud container clusters create ... --labels=test=gke |
| View cluster labels | gcloud container clusters describe ... --format="yaml(...)" |
| Update cluster labels | gcloud container clusters update ... --update-labels=key=val |
| Remove cluster labels | gcloud container clusters update ... --remove-labels=key |
| View node-pool labels | gcloud container clusters describe ... --format="yaml(...)" |
| Remove node-pool label | gcloud container node-pools update ... --remove-labels=key |
Links and References
- GKE Labels Documentation
- Kubernetes Labels and Selectors
- gcloud container clusters
- gcloud container node-pools
Watch Video
Watch video content