download

Why does a database check in livenessProbe crash healthy pods?

DevOps~10 minReviewed 2 Dec 2026Free · No sign-in

Question

A Deployment runs 20 API pods behind a Kubernetes Service. Both probes call /health, which runs SELECT 1 on PostgreSQL. Each pod takes 70 seconds to boot and warm its local cache.

"YAML"
livenessProbe:
  httpGet: { path: /health, port: 8080 }
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3
readinessProbe:
  httpGet: { path: /health, port: 8080 }
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3

PostgreSQL fails over for 45 seconds.

  1. What happens to all 20 pods during the failover, and why do they enter CrashLoopBackOff afterward?
  2. How should you split /livez, /readyz, and startupProbe?
Show hints (3)
  1. "CHECK FAILURE WINDOW"

    Multiply periodSeconds (10) by failureThreshold (3). Compare that 30-second window against both the 45-second failover and the 70-second boot time.

  2. "SEPARATE TWO ACTIONS"

    livenessProbe tells kubelet to kill and restart the container. readinessProbe only removes the Pod IP from Service endpoints.

  3. "PROTECT SLOW BOOT"

    Without a startupProbe, livenessProbe starts right away (initialDelaySeconds defaults to 0) and kills any container still warming up after 30 seconds.

Show checked explanation

During the 45-second failover, every pod fails livenessProbe three times within 30 seconds, so kubelet kills and restarts all 20 healthy pods at once. Because boot takes 70 seconds with no startupProbe, liveness kills them again at 30 seconds, causing CrashLoopBackOff. Keep /livez process-only, move dependency checks to /readyz, and add startupProbe.

"SOLUTION · PYTHON"
def livez(alive):
    return 200 if alive else 500


def readyz(alive, db_ok):
    return 200 if (alive and db_ok) else 503


def sim(pods, ticks, thresh, probe_fn):
    fails = sum(1 for _ in range(ticks) if probe_fn() >= 400)
    return pods if fails >= thresh else 0


ticks = 45 // 10  # 4 probe ticks during a 45s DB failover
bad = sim(20, ticks, 3, lambda: readyz(True, db_ok=False))
good = sim(20, ticks, 3, lambda: livez(True))
print(f"db in liveness: restarts={bad} (ticks={ticks})")
print(f"split /livez:   restarts={good} readyz={readyz(True, False)}")
"OUTPUT"
db in liveness: restarts=20 (ticks=4)
split /livez:   restarts=0 readyz=503

Probe state math and Python 3.12 endpoint simulation run on CPython 3.12.10 (Windows x64) and checked against Kubernetes probe documentation. Checked by an editor other than the author.

Walkthrough

Kubernetes treats HTTP status codes from 200 to 399 as success and 400 or above as failure. With periodSeconds: 10 and failureThreshold: 3, three consecutive failures happen within 30 seconds (3 * 10 = 30). During a 45-second database failover, kubelet runs 4 probe checks (45 // 10 = 4), so all 20 pods cross the threshold and get restarted together.

Restarting an API pod cannot fix a database failover. Worse, 20 pods restarting at the same time flood the recovering database with cold connections and cache rebuilds. Because initialDelaySeconds defaults to 0 and no startupProbe exists, livenessProbe kills each restarting pod again after 30 seconds while it still needs 70 seconds to boot. That traps the fleet in CrashLoopBackOff even after PostgreSQL recovers.

Each Kubernetes probe answers a different question:

ProbeQuestion it answersAction on failure
startupProbeHas the app finished booting?Holds off liveness and readiness; restarts after startup budget
livenessProbeIs this process wedged or deadlocked?kubelet kills and restarts the container
readinessProbeShould this pod receive traffic now?Removes the Pod IP from Service endpoints; no restart

Fix the deployment by giving slow boots a 120-second startupProbe (12 * 10 = 120 > 70), keeping /livez free of external calls, and checking readiness on /readyz:

"YAML"
startupProbe:
  httpGet: { path: /livez, port: 8080 }
  periodSeconds: 10
  failureThreshold: 12
livenessProbe:
  httpGet: { path: /livez, port: 8080 }
  periodSeconds: 10
  timeoutSeconds: 2
  failureThreshold: 3
readinessProbe:
  httpGet: { path: /readyz, port: 8080 }
  periodSeconds: 5
  timeoutSeconds: 2
  failureThreshold: 2

Now a 45-second failover causes 0 container restarts. Pods stay warm and resume serving traffic as soon as /readyz returns 200 again.

Common mistakes

  • Pointing livenessProbe and readinessProbe at the same dependency-checking /health endpoint. One downstream hiccup turns into a fleet-wide restart storm.
  • Setting a huge initialDelaySeconds (like 90 seconds) instead of startupProbe. Every healthy rolling deploy then waits 90 seconds even when a pod boots in 15 seconds.
  • Leaving timeoutSeconds at the 1-second default while /readyz runs a slow query. Brief GC pauses then fail probes falsely.
  • Failing /readyz when an optional dependency (like recommendations) is slow. That pulls healthy pods out of rotation for a non-critical feature.

Follow-up questions

  • "What happens if every pod fails readinessProbe at once during a database blip?" The Service drops to zero ready endpoints, so callers get fast failures at ingress instead of hanging sockets, and pods avoid a restart storm. For optional dependencies, serve degraded responses instead of failing /readyz.
  • "What should a good /livez endpoint actually check?" Check only local process health: can the HTTP server accept requests, is the main event loop responsive, and are critical worker threads not deadlocked? Keep it fast, in-memory, and free of network calls.
  • "Why does Kubernetes require successThreshold to be 1 on liveness and startup probes?" Once a container starts or passes a liveness check, it is considered alive immediately. Only readinessProbe supports successThreshold > 1 so a recovering pod must pass several checks before taking live traffic.

What a strong answer covers

Computes the 30-second kill window against the 45-second failover and 70-second boot time. Explains why database checks in livenessProbe trigger fleet-wide restarts and CrashLoopBackOff, then cleanly separates startupProbe, /livez, and /readyz.

Open in interactive practice deck →

Original OfferVibe question. Configure Liveness, Readiness and Startup Probes · Pod Lifecycle.
© 2026 OfferVibe · Text CC BY-NC-SA 4.0 · code MITFree to share and adapt with credit, not for commercial use. Code samples are free for any use.