liveBook · Manning

Label

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A label is a key-value metadata attribute attached to a Kubernetes object for identification, querying, or selection.

A label is a key=value attribute on a Kubernetes object. Labels identify objects for queries and selection; a label on a node does not change how that node operates. Nodes have default labels, and pods can have labels too. Inspect them with `kubectl get no --show-labels` or `kubectl get po -n kube-system --show-labels`. section 2.1.3

Schedule a pod using a node label

Run `kubectl label no kind-worker disktype=ssd`, then confirm the label with `kubectl get no --show-labels`. In the pod manifest, set `nodeSelector` to `disktype: ssd`. After creating the pod, run `kubectl get po -o wide` and check the NODE column. Unlike `nodeName`, a node selector can match a label applied to multiple nodes; a toleration alone does not select a node. section 4.1 section 4.1.1

Labels also matter when troubleshooting traffic to pods. If a Service cannot reach an application, inspect its selector with `kubectl get svc -o yaml` and compare it with `kubectl get po --show-labels`. Check the Service and application ports as well: a selector is not the only possible cause of failed connectivity. section 8.3.2

root@kind-control-plane:/# kubectl get po --show-labels
NAME                     READY   STATUS    RESTARTS   AGE   LABELS
nginx-6cdcf8f964-hdwzr   1/1     Running   0          20m   app=nginx,pod-
 template-hash=6cdcf8f964

The pod listing displays `app=nginx` alongside another pod label, giving you values to compare with a Service selector. section 8.3.2

For scheduling practice, apply a node label, use it in a pod's node selector, and verify the assigned node. For Service troubleshooting, compare selector values with pod labels before changing either resource. section 4.1 section 8.3.2

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through kubectl inspection, node labeling, scheduling verification, and Service troubleshooting without descending into label API internals.
Examples
Shows an SSD-labeled worker selected by a pod and an nginx Service investigated by comparing its selector with pod labels.
What it assumes
Assumes familiarity with pods, nodes, kubectl, and pod YAML while demonstrating how to inspect and apply labels.
What you can do after
Operate/configure it with kubectl to label nodes, verify pod placement, and inspect labels when Service connectivity fails.
How it connects
Connects labels to node selectors, node affinity, pod affinity, and Service selectors.

Also explained in

Compare how 7 books explain label →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.