Full lesson
Explore the full explanation, examples, and visuals at your own pace.
web-svc.yaml
A Kubernetes Service finds its pods by label, not by name. A label is just a key-value tag attached to a pod. In this file, the selector says app equals web, so any pod carrying that tag becomes a target for traffic sent to web-svc.
apiVersion: v1
kind: Service
metadata:
name: web-svc
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080Which pods match app=web?
Check each pod's label against the selector app=web. web-1 has app=web, so it matches. web-2 matches too. db-1 carries app=db, so it's left out. The IPs here are illustrative, and a matching pod also has to be Ready before it actually receives traffic.
Step 1: matches become an address list
The Service, web-svc, doesn't hold pod addresses itself. An EndpointSlice does, and you can think of it as the Service's address list. A controller in the control plane watches the pods, finds the matches, and fills the slice. It starts empty, then holds two pod IPs: web-1 and web-2.
A saved search, always re-run
A Service is a saved label search. Think of the clerk with his sticky note, app equals web, checking every door and copying down the matching rooms, while skipping the app equals db door. The EndpointSlice is his clipboard, and he re-runs that search whenever pods change.
Step 2: kube-proxy learns the list
Once web-svc selects its pods, the EndpointSlice holds their two IPs. kube-proxy is an agent that runs on every node, and it watches that slice. When it receives the list, it writes forwarding rules mapping ClusterIP 10.96.0.10 to those two pod IPs. Before, there were no rules. Now there are.
Step 3: a request reaches a pod
Now the client sends GET slash to the ClusterIP, 10.96.0.10. The rules kube-proxy wrote catch that packet and rewrite the destination to one listed pod IP, say web-1, on port 8080. The next request may go to web-2. Both are in the list, so either can answer.
Change a label, change the traffic
Before the change, kube-proxy forwards to both web-1 and web-2, since both carry app=web. Now relabel web-2 to app=debug. It drops out of the EndpointSlice, the rules update, and web-2 no longer gets traffic. Only web-1 does. A new app=web pod would join automatically.
A Service is a saved label search with a live address list.
A Service is a saved label search with a live address list. So when a Service isn't getting traffic, start by comparing its selector with the pod labels, and check that the pods are Ready. A mismatch there is the most common culprit.
