Sub topic 5
Readiness probes and who receives traffic
This chapter assumes you can read a Deployment manifest, use kubectl get, describe, and logs, and know that a Service selects Pods by label. The previous chapters covered selectors and port mapping. Here you will see why a Pod that matches the selector can still receive no traffic.
Running is not the same as ready
A Pod can be in the Running phase while its application is still starting, loading data, or failing. Kubernetes tracks this with a separate condition called Ready. A Service only sends traffic to Pods whose Ready condition is true.
A readiness probe is a periodic check the kubelet runs against a container. While the probe fails, the Pod is marked not ready and is removed from the Service's endpoints. The Pod is not restarted. That is the difference from a liveness probe, which restarts the container when it fails.
The Deployment from earlier in this tutorial includes this probe:
readinessProbe:
httpGet:
path: /
port: 80The kubelet sends GET / to port 80 of the container. Any HTTP status from 200 to 399 counts as success. Anything else, or a timeout, counts as failure.
How readiness reaches the Service
The endpoints controller watches Pods that match the Service selector. It records each Pod IP in an EndpointSlice and marks it ready or not ready. kube-proxy only programs rules for ready addresses.
Symptoms and how to confirm them
A Service whose Pods are all unready looks healthy from the outside. The Service exists and has a cluster IP, but connections fail or time out because there is nowhere to send them.
Check the Pod's READY column first:
kubectl get pods -l app=webA value such as 0/1 means the container is running but not ready. Then find out why:
kubectl describe pod -l app=web
kubectl get endpointslices -l kubernetes.io/service-name=web -o yamlIn describe, look for events like Readiness probe failed: HTTP probe failed with statuscode: 404 or connection refused. In the EndpointSlice, an unready Pod appears with ready: false in its conditions.
Common causes of a failing probe
- Wrong port. The probe targets a port the application does not listen on. This gives
connection refused. - Wrong path. The probe requests a path that returns 404 or 500.
- Slow startup. The application needs longer than the probe allows. Tune
initialDelaySeconds,periodSeconds, andfailureThreshold, or use astartupProbe. - A dependency is down. The health endpoint checks a database or another service, and that check fails. All replicas go unready together.
- Application bound to localhost. The app listens on
127.0.0.1only, so the probe, which connects to the Pod IP, is refused.
Try it
Break the probe on purpose by pointing it at a path that does not exist:
kubectl patch deployment web --type=json -p='[{"op":"replace","path":"/spec/template/spec/containers/0/readinessProbe/httpGet/path","value":"/missing"}]'
kubectl get pods -l app=web
kubectl get endpointslices -l kubernetes.io/service-name=webThe rollout creates new Pods that show 0/1. During a rolling update the old Pods stay ready until the new ones pass, so the Service keeps working. Once you fix the path, the new Pods become ready and the rollout finishes.
Exercise
A Service named api has a cluster IP, and nslookup api resolves correctly. Requests to it time out. kubectl get pods -l app=api shows 0/1 Running for all three Pods, and the EndpointSlice lists no ready addresses. What is the most likely layer of the problem, and which command shows the reason?
Show answer
The readiness probe is failing, so the Pods are not ready and the Service has no ready endpoints. DNS and the selector are fine. Run kubectl describe pod on one of the Pods and read the events for the Readiness probe failed message, then fix the probe's port or path, or the application itself.