الانتقال إلى المحتوى
DevOps والـ CloudKubernetes· 7 دقائق للقراءة

Liveness Is Not Readiness: Health Checks That Don't Restart Your Whole Fleet

Liveness decides restarts and readiness decides traffic. Put a database check in liveness and one outage restarts every replica.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A team adds a /health endpoint to its API that runs a quick query against the database, and wires it up as the liveness probe: if the API can't reach its data, it isn't healthy, so restart it. One evening the database fails over to a replica and is unreachable for a few minutes. Every API Pod fails the probe at the same moment, and every one is restarted, then restarted again. When the database is back, the API is still busy starting up. The incident review asks why Kubernetes made a short database blip so much worse.

The common misconception

The belief: an app has one health, so one /health endpoint that checks everything it depends on is the best liveness probe. The deeper the check, the more problems it catches.

It's an understandable belief. "Health" sounds like a single yes-or-no answer, and many tutorials expose exactly one health endpoint. Deep checks really do catch more: an API that can't reach its database can't do its job. And restarting sometimes does help, for example when a process is stuck. So "unhealthy means restart" feels safe.

The half-truth: a deep check is a good signal. It's the wrong trigger for a restart, because restarting your process doesn't repair someone else's.

What actually happens

Three probes, three different actions

The kubelet runs each probe periodically on the container, and each one leads to a different action. "determine when to restart a container", for example to catch "a deadlock, where an application is running, but unable to make progress." After failureThreshold failures in a row, 3 by default, the container is restarted. "determine when a container is ready to accept traffic." When one fails, the docs say the kubelet "continues running the container that failed checks" and sets the Pod's Ready condition to false. A startup probe holds back the other two until a slow app has finished starting.

Restarts don't fix a dependency

Microsoft's Health Endpoint Monitoring pattern puts it in one line: "A responsive process isn't necessarily ready to serve requests, and restarting it doesn't repair a failed shared dependency." And a shared dependency fails for every replica at the same moment. The Kubernetes docs warn that liveness probes should "truly indicate unrecoverable application failure, for example a deadlock", and that "incorrect implementation of liveness probes can lead to cascading failures."

Readiness takes a Pod out of rotation

When readiness fails, the Pod stays listed in its Service's EndpointSlice with ready: false. The EndpointSlice docs explain that the serving condition "maps to the Pod's Ready condition" and tells proxies whether the endpoint "should be used as a target for Service traffic." The container keeps its state, connections and warm caches, and gets traffic again as soon as the probe passes. The probe docs describe the pattern: "The liveness probe passes when the app itself is healthy, but the readiness probe additionally checks that each required back-end service is available."

Watching both on a cluster

We ran this on Docker Desktop's Kubernetes (server v1.34.3, kubectl v1.34.1); --context and -n are left out for space. The api Deployment runs 2 replicas of busybox:1.37, serving two small CGI scripts with httpd: /cgi-bin/health returns 200 only if wget reaches http://db/ within 1 second, otherwise 503, and /cgi-bin/live always returns 200. db is an nginx:1.29.8-alpine Deployment that we scaled to zero to fake an outage. These are the probe sections of the two versions we applied:

YAML api.yaml
livenessProbe:            # one deep check decides restarts  httpGet:    path: /cgi-bin/health    port: 8080  periodSeconds: 5  timeoutSeconds: 2

And this is what happened when the database went away:

Bash terminal
kubectl scale deployment db --replicas=0kubectl get pods -l app=api   # 2.5 minutes later# NAME                   READY   STATUS    RESTARTS      AGE# api-76656748dc-j4t48   1/1     Running   3 (17s ago)   2m54s# api-76656748dc-qx4km   1/1     Running   3 (17s ago)   2m53s

In the first tab, both replicas restarted in lockstep, three times each in two and a half minutes. Their events read "Liveness probe failed: HTTP probe failed with statuscode: 503", then "Container api failed liveness probe, will be restarted". And because there was no readiness probe, both stayed 1/1 ready the whole time, so the Service kept sending them requests between restarts. In the second tab, both Pods went 0/1 with zero restarts. Note that the plain kubectl get endpointslices table still lists both IPs; only the conditions show they're out of rotation. When the database returned, both were back in rotation seven seconds later, never having restarted.

ProbeQuestion it answersWhen it failsCheck dependencies?
StartupHas the app finished starting?The container is killed and restartedNo, use the liveness endpoint
LivenessIs this process stuck beyond repair?The container is restartedNo, never shared ones
ReadinessCan this Pod serve a request right now?It stops getting Service traffic, keeps runningRequired ones, with short timeouts

How to apply it in your project

  1. Split the endpoint in twoExpose /live, which does no I/O and only proves the process answers, and /ready, which checks initialization and the dependencies a request can't do without. Give each dependency check its own short timeout.
  2. Audit your liveness probesRun kubectl describe deploy | grep -E "^Name:|Liveness:|Readiness:" to list each Deployment's probes with their paths and timings. Any liveness endpoint that talks to a database, a cache or another service belongs in a readiness probe instead.
  3. Use a startup probe for slow startsIf startup is slow, don't stretch the liveness delay. Add a startup probe on the same cheap endpoint with a high failureThreshold, so liveness only starts once the app is up.
  4. Treat synchronized restarts as a probe bugIf every replica's RESTARTS count climbs together, check the events for "Liveness probe failed". The cause is almost always outside the Pods, and the probe is turning it into an outage.

Key takeaways

  • Liveness decides restarts; readiness decides traffic. They answer different questions and need different checks.
  • A liveness probe that checks a shared dependency fails on every replica at once and restarts the whole fleet.
  • A failed readiness probe keeps the container running and marks its endpoint not ready until it passes again.
  • Keep liveness shallow, put required dependencies in readiness, and give every check a short timeout.
  • If all replicas fail readiness together, the Service has nothing to route to, so check only what you can't work without.

📚 المصادر

  1. Liveness, Readiness, and Startup Probes — Kubernetes Documentation
  2. Configure Liveness, Readiness and Startup Probes — Kubernetes Documentation
  3. EndpointSlices — Kubernetes Documentation
  4. Health Endpoint Monitoring pattern — Azure Architecture Center

التعليقات (0)