Kubernetes: Fix the Selector Mismatch
A selector mismatch is a Deployment whose selector labels and pod template labels disagree. The Deployment then reports zero ready replicas and no readable error.
See zero ready replicas
The Deployment shows the desired count but zero ready. No error explains why.
kubectl get deployment webCompare the labels
The pod labels show what the pods carry. The selector needs the same labels.
kubectl get pods --show-labelsCheck the endpoints
An empty endpoint list confirms the Service found no pods. The selector is the first suspect.
kubectl get endpoints webFix the labels
The template label changes to match the selector. The new pods join the Deployment at once.
kubectl get deployment webExample
kubectl get deployment web
kubectl get pods --show-labels
kubectl get endpoints webKey points
- Selector mismatch: the Deployment selector and the pod template labels do not match, so the Deployment owns no pods
- Use spec.selector.matchLabels to state which pods the Deployment manages
- Use the pod template labels to mark the pods the Deployment creates
- A mismatch shows zero ready replicas with no error message
- Use kubectl get pods --show-labels to compare the labels on the running pods
- Use kubectl get endpoints to check whether a Service found any pods
- An empty endpoint list means a selector mismatch or a failed readiness probe
In this example, the first command shows zero ready replicas. The second command shows the pods carry the label app with the value website. The third command shows no endpoints. The pods are running, so the labels are the fault and not the app.
Note
The selector is fixed at creation, so a bad selector needs a fresh Deployment.
Try it Yourself
Edit the code, then press Run.
Running is simulated ยท Rust Playground
Exercise
A Deployment shows 0/2 ready, its pods are Running, and its Service has no endpoints. What is the most likely fault?