Sub topic 5
How Services decide which Pods receive traffic
This chapter assumes you know how to create Pods, Deployments, and Services, and that you can read kubectl output. It explains how a Service picks its backends. That is the mechanism a readiness probe controls, so the later chapters build on it.
A Service does not check health
A Service is a stable virtual IP and DNS name. It does not test Pods itself. Membership is decided by a chain of components:
- The Service's label selector matches Pods.
- The EndpointSlice controller records each matching Pod's IP in an EndpointSlice.
- Each entry carries conditions, including
ready. kube-proxy(or your cluster's network plugin) reads the slices and routes traffic only to ready endpoints.
The kubelet closes the loop. It runs the readiness probe and reports the result in the Pod's Ready condition, and the EndpointSlice controller copies that into the endpoint's ready condition.
A Service and its Pods
This Service selects the Pods from the Deployment used in this tutorial:
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080Any Pod in the namespace with the label app: web is a candidate. A candidate becomes a routable backend only when it is ready.
When a Pod counts as ready
A Pod is Ready when every container in it reports ready. A container is ready when its readiness probe is passing. If a container has no readiness probe, it is ready as soon as it is running. That default is why a Pod without a probe can receive traffic before the application can serve it.
A Pod can also have readiness gates, extra conditions that an external controller must set to true. Most clusters use these only with load balancer integrations.
Inspecting membership
Look at the EndpointSlices for the Service:
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl get endpointslices -l kubernetes.io/service-name=web -o yamlIn the YAML, each entry under endpoints has a conditions block with three fields:
| Condition | Meaning |
|---|---|
| `ready` | The Pod is Ready and is not terminating. Normal traffic goes only to these. |
| `serving` | The Pod can still handle requests, even while terminating. |
| `terminating` | The Pod has a deletion timestamp. |
A Pod that fails readiness stays in the slice with ready: false. It is not removed, and it is not restarted. It just stops receiving new traffic. When the probe passes again, the flag flips back.
What readiness failure does and does not do
- It removes the Pod from load balancing for new connections.
- It does not kill the container. Restarts come from liveness and startup probes, covered in later chapters.
- It does not stop traffic that bypasses the Service, such as a client that connects to a Pod IP directly.
- If every Pod is not ready, the Service has no ready endpoints, and connections to it fail or time out.
Propagation takes time. The probe period, the failure threshold, the controller update, and the proxy rule refresh all add delay. A Pod can receive a few requests after it starts failing.
Special cases
A headless Service (clusterIP: None) still uses EndpointSlices. DNS returns only the ready Pod IPs.
Setting publishNotReadyAddresses: true on a Service publishes endpoints even when they are not ready. StatefulSet peer discovery uses it, because Pods must find each other before they are ready. Do not enable it on a normal user-facing Service.
A Service without a selector gets no automatic EndpointSlices, so no Pod readiness applies. You manage its endpoints yourself.
Exercise
A Pod's readiness probe starts failing. In the Service's EndpointSlice, what happens to that Pod's entry, and does the container restart?
Show answer
The entry stays in the slice, but its ready condition becomes false, so the Service stops routing new traffic to it. The container does not restart. Only a failing liveness or startup probe causes a restart. When the readiness probe passes again, ready returns to true.