A label selector is a Kubernetes matching expression that identifies or associates objects by labels. Selectors connect Services to matching pods and can guide pod scheduling onto nodes with particular labels. section 4.3 section 6.4.1
Use label selectors to perform these operational tasks:
- Associate a Service with pods carrying the required label, such as app=internal-svc. section 6.4.1
- Route Service traffic to the intended Deployment or pods; a selector mismatch can leave the Service without endpoints. section 8.3.3
- Influence scheduling by labeling nodes and selecting nodes with matching labels. section 4.3
- Inspect pod labels with kubectl get po --show-labels and compare them with the Service selector. section 8.3.2
Diagnose a Service selector mismatch
When a Service cannot reach its application, inspect its YAML with kubectl get svc -o yaml and inspect pod labels with kubectl get po --show-labels. If the Service selects app=nginx, the target pod must carry app=nginx. Correct the selector or labels, then retry the request; a successful curl returns the nginx welcome page. section 8.3.2 section 8.3.3
spec:
ports:
- name: 8080-80
port: 8080
protocol: TCP
targetPort: 80
- name: search
port: 9200
protocol: TCP
targetPort: 9200
selector:
app: internal-svc
type: ClusterIP
status:
loadBalancer: {}
Inspect the Service YAML to see the selector field alongside ports and targetPort values. section 6.4.1






