selector
What is selector?
selector: A query over labels. Services, Deployments, and NetworkPolicies use selectors to find the Pods they apply to. A selector in Kubernetes is a query over labels that picks a set of objects. selector: matchLabels: app: web matches every pod labelled app=web. Selectors are how Kubernetes objects find each other. A Service sends traffic to pods matching its selector, a Deployment manages pods matching its selector, and a NetworkPolicy applies to the pods it selects.
Frequently asked questions about selector
What should you keep in mind with selector?
Most confusing Kubernetes problems involving "no endpoints" or "traffic goes nowhere" come down to a selector that does not match the labels on the pods, often because of a typo or a label changed in one place only. Compare them with kubectl get pods --show-labels and kubectl describe service. Remember that a Deployment's selector cannot be changed after creation, so choose stable labels from the start.
What does an example of selector look like?
selector: matchLabels: app: web At a glance
| Category | Kubernetes |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |