Skip to content

Kubernetes Pod labeling

Pod labeling is the mechanism used to attach identifying metadata to Kubernetes Pods. These key-value pairs are used by controllers, such as Deployments, to manage and select specific groups of Pods^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md].

Automatic Labeling

When a Deployment creates a ReplicaSet, it automatically applies labels to all Pods it spawns.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md] In standard configurations, such as an nginx-deployment, the Pods are typically labeled with the application name (e.g., app=my-nginx) and a unique template hash (e.g., pod-template-hash=8475f9f6cc).^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md] The template hash ensures that the controller can distinguish between different versions of the application.

Viewing Labels

To inspect the labels assigned to running Pods, the --show-labels flag is used with the get command^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]:

[kubectl](<./kubectl.md>) get [Pod](<./pod.md>) --show-labels

This will output the list of Pods alongside their attached key-value pairs^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md].

  • [[Services]]
  • [[Deployments]]
  • [[Selectors]]

Sources

^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]