Labels and selectors
The stickers that connect everything.
Labels are the humble little stickers that connect almost everything in Kubernetes, and once you see how they work, a lot of the "magic" stops being mysterious. A label is a key-value tag you put on an object; a selector is a search for objects with certain tags. That is the whole idea, and it is everywhere.
Stickers and searches
You attach labels to pods (and other objects) as simple key-value pairs — app: hello, tier: frontend, env: prod — and then other things find those pods by matching the labels. This is how a Deployment knows which pods it owns, how a Service knows which pods to send traffic to, and how you filter with kubectl get -l. The connections in Kubernetes are not hard-wired references; they are label searches. A Service does not point at specific pods by name or address — it says "send traffic to any pod labelled app: hello", and whichever pods currently wear that sticker receive the traffic. That indirection is exactly what lets pods come and go freely: new pods that wear the label are automatically included, and departed ones simply stop matching.
kubectl label pod hello tier=frontend # add a stickerkubectl get pods -l app=hello # find pods by sticker (a selector)kubectl get pods -l 'env in (prod,staging)' # match a set of values# The SAME matching connects objects — no hard-wired names:# Service → selector: { app: hello } "route to any pod labelled app=hello"# Deployment → selector.matchLabels "these are the pods I own"# Whichever pods currently wear the label are the ones that match.
Why this matters so much
Understanding labels unlocks how Kubernetes stays flexible and self-healing. Because everything connects by label matching rather than fixed identity, the system tolerates constant change: pods are replaced with new ones (different names, different IPs), and as long as the replacements wear the same labels, every Service and controller keeps working without you updating anything. It is also how you organize a cluster — labels like env, team, or version let you select, group, and act on exactly the right objects. There is a subtle gotcha to respect: changing a running pod’s labels can quietly disconnect it (a Service stops sending it traffic, or its Deployment no longer counts it and makes a replacement), so change labels deliberately. But the everyday takeaway is cheerful: labels are simple stickers, selectors are simple searches, and together they are the glue that lets Kubernetes wire up ever-changing pods reliably. When you later wonder "how does this thing know about that thing?", the answer is almost always a label selector.