Take a moment to think about this
In Kubernetes, you can attach key-value label pairs to resources (pods, deployments, services) — for example `app: web`, `env: production`, `tier: frontend`. A Selector is a query that says 'pick every resource with this label' — a Service uses it to find its pods, and a Deployment uses it to know which pods belong to it. Labels aren't unique like resource names — 50 pods can share the same label, and a Selector can pick all 50 of them at once.
Let's connect this to a real scenario
Running `kubectl get pods -l app=web` filters down to just the pods with the app=web label — label filtering matters a lot when troubleshooting production clusters with hundreds of pods. Teams usually agree on a convention — keeping labels like `app`, `env`, `team`, `version` consistent makes everything much easier to search.
Let's look at it together
# Filter pods by label
kubectl get pods -l app=web
# Multiple labels (AND condition)
kubectl get pods -l app=web,env=production
# Add a label to an existing pod
kubectl label pod my-first-pod team=backend
# See labels on all pods
kubectl get pods --show-labelsNAME READY STATUS LABELS
web-deployment-7d9f8c6b5-abc12 1/1 Running app=web,env=production
web-deployment-7d9f8c6b5-def34 1/1 Running app=web,env=production5-minute try-it
Tag every Pod/Deployment with two labels, app and env, and try filtering with a few different `kubectl get pods -l` commands.
A quick word of caution
A Deployment's selector field can't be changed after it's created (it's immutable) — think it through carefully from the start.