Liveness and readiness probe failed: what each one does
Reproduced on k3s v1.31.5 (k3d) with kubectl v1.36.1.
What you see
$ kubectl get pod probe-demo -n lab
NAME READY STATUS RESTARTS AGE
probe-demo 0/1 Running 5 (10s ago) 2m35s
$ kubectl describe pod probe-demo -n lab
Last State: Terminated
Reason: Completed
Exit Code: 0
Restart Count: 5
Liveness: http-get http://:80/healthz delay=5s timeout=1s period=5s #success=1 #failure=3
Readiness: http-get http://:80/ready delay=0s timeout=1s period=5s #success=1 #failure=3
Events:
Normal Killing 100s kubelet spec.containers{web}: Container web failed liveness probe, will be restarted
Warning Unhealthy 90s (x5 over 110s) kubelet spec.containers{web}: Liveness probe failed: HTTP probe failed with statuscode: 404
Warning Unhealthy 85s (x12 over 116s) kubelet spec.containers{web}: Readiness probe failed: HTTP probe failed with statuscode: 404What it means
The kubelet runs each probe on its own schedule. After failureThreshold failures in a row, a liveness probe triggers a container restart. A readiness probe marks the pod not ready, so Services stop sending it traffic. A startup probe holds off the other two until the app has started.
A liveness restart is a normal stop. The container gets its stop signal and the grace period. So the exit code depends on how the app handles the signal. In our lab nginx exited 0 with reason Completed after each liveness kill, which can look like a clean exit if you only read Last State.
Readiness failures alone never restart anything. A pod showing 0/1 Running with no restarts is usually a readiness problem.
Common causes
Wrong path, port or scheme
The probe points to an endpoint the app does not serve, the wrong port, or HTTP when the app only speaks HTTPS.
How to tell: statuscode: 404, connection refused or a TLS error in the Unhealthy event, from the first check onward.
App is slow to start
The liveness probe starts checking before the app is ready to answer. The app is killed during startup, again and again.
How to tell: Restarts happen at about the same time after each start. Logs show startup work still running.
Timeout too short
The default timeoutSeconds is 1. Under load or during garbage collection, the health endpoint takes longer.
How to tell: The event says context deadline exceeded or Client.Timeout exceeded, mostly during busy periods.
Liveness checks a dependency
The liveness endpoint checks the database or another service. When that dependency has trouble, every replica restarts at once.
How to tell: All replicas restart together and the health endpoint returns 500 or 503 with a dependency error.
Readiness checks a slow dependency
The readiness endpoint waits on the database or another service. When that dependency slows down, every replica fails readiness together. The Service is left with no ready endpoints, so all traffic fails even though the pods are fine.
How to tell: No restarts, but all pods show 0/1 Running at once. The EndpointSlice has no ready endpoints and readiness failures match a slow dependency.
Exec probe command fails
An exec probe runs a command that is missing from the image or returns non-zero for another reason.
How to tell: The event shows the command output or executable file not found.
How to diagnose it
kubectl describe pod <pod> -n <namespace>Read the Liveness and Readiness lines for path, port and timings. Then read Unhealthy and Killing events to see which probe fails and with what result.
kubectl get events -n <namespace> --field-selector involvedObject.name=<pod>,reason=Unhealthy --sort-by=.lastTimestampOnly probe failures, in time order. Look at whether they started right after deploy or during load.
kubectl get events -A --field-selector reason=Unhealthy --sort-by=.lastTimestampProbe failures across the whole cluster. Many workloads failing at once points to a shared dependency or node trouble, not one bad probe.
kubectl port-forward pod/<pod> -n <namespace> 8080:<container-port>Then curl -v http://localhost:8080/<probe-path> from your machine. You see the same status code and timing the kubelet sees.
kubectl logs <pod> -n <namespace> --previousLogs from before the last liveness restart. Look for startup still running, long pauses or errors from the health handler.
kubectl get endpointslices -n <namespace> -l kubernetes.io/service-name=<service>For readiness problems, check how many endpoints are ready. Not ready pods are listed with ready set to false.
How to fix it
Point the probe at the right endpoint
Match path, port and scheme to what the app serves. Use a named port so the probe follows port changes.
Trade-off: None beyond the change itself. Check it in a test environment first so you do not swap one bad probe for another.
Add a startup probe
Let slow apps start without liveness checks. The startup probe allows failureThreshold times periodSeconds to start.
startupProbe:
httpGet: {path: /healthz, port: http}
periodSeconds: 5
failureThreshold: 30
livenessProbe:
httpGet: {path: /healthz, port: http}
periodSeconds: 10
timeoutSeconds: 3Trade-off: A truly hung startup takes that long to be detected and restarted.
Keep liveness shallow
Have liveness answer only whether the process itself is working. Give liveness and readiness their own endpoints, for example /healthz/live and /healthz/ready. Put dependency checks in readiness, or nowhere.
Trade-off: A pod with a broken dependency stays running. You need readiness or alerts to catch it.
Relax timeouts and thresholds
Raise timeoutSeconds and failureThreshold so short pauses do not cause restarts.
Trade-off: Real hangs are detected and fixed more slowly.
How to stop it coming back
- Write a separate, cheap health endpoint for liveness. Do not reuse a page that does real work.
- Test probes against the real image in CI with the same path and port as the manifest.
- Watch for Unhealthy events after each rollout, before they turn into restarts.
- Give any app with slow startup work, such as loading caches or warming a JVM, a startup probe from the first deploy.
How KubeGraf investigates it
Agents propose competing explanations and cite the evidence behind each one. How KubeGraf handles Kubernetes incidents.
Frequently asked questions
What happens when a liveness probe fails?
After failureThreshold failures in a row, the kubelet stops and restarts the container. The container gets its normal stop signal and grace period. Repeated restarts can lead to CrashLoopBackOff.
What does probe failed connection refused mean?
Nothing was listening on that port when the kubelet checked. Either the probe has the wrong port or the app had not started listening yet. If it fails from the very first check, look at the port first.
What is a startup probe for?
A startup probe holds off the liveness and readiness probes until the app has started. It gives slow apps failureThreshold times periodSeconds to start.
Why is my pod Running but not ready?
A pod showing 0/1 Running with no restarts is usually failing its readiness probe. It stays out of the Service until the probe passes. Check the Unhealthy events and the endpoint the probe calls.
Last updated . Try KubeGraf Freemium.
Related
- CrashLoopBackOff
- Exit Code 137 / Exit Code 143
- Init:CrashLoopBackOff
- Probes that kill healthy pods
- Kubernetes Root Cause Analysis: A Complete Guide