Menu
Coddy logo textTech

Labels

Part of the Introduction to Kubernetes section of Coddy's Terminal journey. Lesson 9 of 45.

Labels are key/value tags you attach to objects in metadata. They mean nothing to Kubernetes by themselves, but almost everything else (finding Pods, connecting Services to them) works through labels:

metadata:
  name: web
  labels:
    app: web
    tier: frontend

Show the labels of every Pod with --show-labels, or filter by label with -l (a selector):

kubectl get pods --show-labels
kubectl get pods -l app=web

The second command lists only the Pods whose app label equals web.

You can add or change a label on a live object without touching its manifest:

kubectl label pod web tier=frontend

kubectl run also accepts -l app=web to label the Pod as it is created. A file can hold several manifests separated by a line with ---; apply creates them all.

challenge icon

Challenge

Easy

A manifest named pods.yaml describes two Pods, web and db, each with an app label. Apply it, list the Pods with their labels, then list only the Pods whose app label is db.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to Kubernetes

Practice on your own: Terminal playground