Sub topic 9
How readiness, liveness, and startup probes show up
This chapter assumes you can read Pod phase, container states, and conditions, and that you can run kubectl describe and read the Events section. It covers what each probe type changes in status and which events it produces.
What each probe does
A probe is a check the kubelet runs against a container. The kubelet is the agent on each node that runs your Pods. Each probe type has a different consequence when it fails.
| Probe | Question it asks | Effect of failure |
|---|---|---|
| Startup | Has the app finished starting? | The container is killed and restarted. Until the probe succeeds, liveness and readiness checks are disabled. |
| Liveness | Is the app still working? | The container is killed and restarted. |
| Readiness | Can the app take traffic now? | The container is marked not ready. It is not restarted. |
A probe can use an HTTP request, a TCP connection, a command run inside the container, or a gRPC call.
Where probes appear in status
Readiness is the only probe result that shows up as a condition. A failing readiness probe sets ready: false on the container and turns the Pod's Ready and ContainersReady conditions to False. The Pod phase stays Running.
Liveness and startup failures do not have their own condition. They appear as a restart: restartCount goes up, and lastState.terminated records the previous exit.
A not-ready Pod is removed from the endpoints of any Service that selects it. The Pod keeps running, but it receives no traffic. This is why a Deployment can show 0/3 ready Pods while every Pod reports Running.
Reading probe failures in events
Probe failures are recorded as Warning events from the kubelet. Run this to see them:
kubectl describe pod web-0
kubectl events --for pod/web-0Typical messages look like this:
Readiness probe failed: HTTP probe failed with statuscode: 503Liveness probe failed: Get "http://10.1.2.3:8080/healthz": context deadline exceededContainer app failed liveness probe, will be restartedStartup probe failed: connection refused
The event reason for all of these is Unhealthy. The Killing reason follows a liveness or startup failure, because the kubelet then stops the container. To list only these events:
kubectl get events --field-selector reason=UnhealthyThe probe settings themselves are in the describe output, on lines starting with Liveness:, Readiness:, and Startup:. They show the endpoint and the delay, timeout, period, #success, and #failure values.
A worked example
This Pod has a liveness probe that fails after the app stops answering. The failureThreshold of 3 means three consecutive failures are needed before the kubelet acts.
apiVersion: v1
kind: Pod
metadata:
name: probe-demo
spec:
containers:
- name: app
image: registry.k8s.io/e2e-test-images/agnhost:2.39
args: ["liveness"]
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
failureThreshold: 3The liveness mode of this test image serves /healthz successfully for a short time and then returns errors. After you apply the manifest, the restart count climbs. Check it with a jsonpath query:
kubectl get pod probe-demo -o jsonpath='{.status.containerStatuses[0].restartCount}'Common mistakes
- A liveness probe that checks dependencies. If it fails whenever a database is down, every Pod restarts at once and the outage gets worse. Keep liveness checks local to the process.
- No startup probe on a slow app. The liveness probe can kill the container before it finishes starting, which produces a restart loop. A startup probe with a generous
failureThresholdfixes this. - Reading
Runningas healthy. Phase says nothing about readiness. Check theReadycondition. - Probe timeouts too short. A
timeoutSecondsof 1 fails under brief load. The events showcontext deadline exceededrather than an error status code.
Exercise
A Deployment shows 0/3 Ready, all three Pods have phase Running, and restartCount is 0. Which probe is most likely failing, and where do you confirm it?
Show answer
The readiness probe. A liveness or startup failure would raise restartCount. Confirm it with kubectl describe pod, where the Ready condition is False and the Events section shows Unhealthy warnings such as "Readiness probe failed".
Exercise
A container's restartCount keeps rising, and describe shows "Liveness probe failed" followed by "Killing". Which field records why the previous instance ended?
Show answer
status.containerStatuses[0].lastState.terminated, which holds the reason and exitCode of the previous instance. Read it with kubectl get pod -o jsonpath, and read its output with kubectl logs --previous.