Full lesson
Explore the full explanation, examples, and visuals at your own pace.
Terminal output
Kubernetes rejected your Deployment over two words. You ran kubectl apply, and the terminal says the Deployment "web" is invalid. Read the last line closely: the selector does not match the template labels. In other words, the Deployment is pointing at Pods that its own blueprint would never produce.
$ kubectl apply -f web-deployment.yaml
The Deployment "web" is invalid:
spec.template.metadata.labels: Invalid value:
map[string]string{"app":"webapp"}:
`selector` does not match template `labels`web-deployment.yaml
Here's the cause. Under selector, matchLabels says app: web. A label is just a key-value tag on an object. But the template, which is the blueprint for each Pod, labels its Pods app: webapp. The Deployment looks for one tag and stamps out another.
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: web
image: nginxSame key, different value
Put the two name tags side by side. On the left, the selector looks for app: web. On the right, the Pod template stamps app: webapp. The key, app, is the same, but the values differ. Kubernetes compares labels exactly, so web and webapp are not a match.
The selector is how it finds its Pods
The Deployment creates Pods from its template, so these Pods would carry app: webapp. But to count and manage them, it searches with its selector, app: web. That search would find nothing. The Deployment could never see its own Pods, so Kubernetes rejects it upfront instead of letting that broken setup run.
Fixed: template labels include the selector
Here's the repair. The selector still asks for app: web, and now the Pod template's labels include app: web, spelled exactly the same. The template also adds tier: frontend. That's fine, because extra labels are allowed. What matters is that every selector label appears in the template.
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
tier: frontendA Deployment can't manage Pods it doesn't recognize.
A Deployment can't manage Pods it doesn't recognize. So copy every selector label into the template, character for character, and add extras only if you want.

