3

In our GCP project we are in the process of setting labels for resources to assist organization and cost management. This is about GCP labels as described here https://cloud.google.com/compute/docs/labeling-resources and not Kubernetes labels.

For standalone resources like instances, persistent disks and external IP addresses we simply set the labels. We have a Kubernetes/GKE cluster which we also labeled. But is seems that the cluster's labels are not inherited by the Kubernetes node instances and their disks automatically. And it seems we cannot put labels on the cluster's node pool. But we would also like to have labels on these resources because ultimately the instances and disks are what's billed. Now we are wondering what the best practice is in this case.

Is it safe to manually add labels on the compute instances which are managed by the cluster's node pool, and their persistent disks, or can this cause problems? If it's ok and if we add the labels, what happens if the node pool is replaced by a new pool and deleted? In that case the instances are automatically deleted and new ones created. Will the new instances and disks inherit the labels of the old instances or will the labels be lost?

Dave M
  • 4,514
  • 22
  • 31
  • 30
f.sh
  • 45
  • 5

1 Answers1

0

Google Kubernetes Engine labels are distinct from labels in Kubernetes. GKE labels are arbitrary metadata attached to your resources that you can use to track usage and billing information. In Kubernetes, the system uses labels internally to associate cluster components and resources with one another and manage resource lifecycles.

In GKE, you apply labels at the cluster level. When you label a cluster, the label you have chosen propagates to all of the cluster's individual resources (such as nodes and persistent disks).

Important:

Any labels you apply to your clusters propagate via a background process that runs hourly. It can take up to one hour for a label to appear on all resources associated with a given cluster. In addition, during the Beta release of cluster labels, labels only propagates to Compute Engine instances and Persistent Disks. Other resources such as forwarding rules and IPs are not labeled.

You can learn more at: GCP Kubernetes Engine Creating and Managing Labels


Reproduction:

  • I've added the label labelkey:labelvalue to a running cluster called cluster-116:
$ gcloud container clusters update cluster-116 --update-labels labelkey=labelvalue --zone us-central1-c
Updating cluster-116...done.  

NOTE: The label update will overwrite any pre-existing labels. If the cluster has existing labels you want to keep, you must include those labels along with any new labels that you want to add.

  • I tried reading the labels instantly on the node Compute Engine VM:
$ gcloud compute instances describe gke-cluster-116-default-pool-2640aefe-87tx --zone us-central1-c | grep label
labels:
  - key: kube-labels ...
  • My label wasn't there yet. I checked again after one hour:
$ gcloud compute instances describe gke-cluster-116-default-pool-2640aefe-87tx --zone us-central1-c | grep label
labels:
  labelkey: labelvalue
  - key: kube-labels ...

As you can see, the label was propagated to the VM Instance.

If you have any question, let me know in the comments.

Will R.O.F.
  • 264
  • 1
  • 8
  • Thank you so much. It seems we were too impatient. I just re-checked and you're correct. Both the node instances as well as their disks now have the same labels as the cluster. – f.sh Jul 08 '20 at 10:06
  • I have several GKE clusters and K8S PV(C), but no GCE PD have GKE cluster labels ... – Logan Mzz Oct 03 '22 at 13:50