Skip to content

The self-healing restart that prevented recovery

Failure story 23, in observability and recovery.

Kubernetes restarted the pod because it was unhealthy, which is what self-healing is for. The pod has now been restarted 14 times and has never served a request. Why?

Assumption Value
Service A search service that loads and rebuilds its in-memory index when it starts: about 90 seconds
Health endpoint /health returns 200 only when the index is ready to serve
Probe One liveness probe on /health: first check after 10 seconds, every 10 seconds, restart after 2 failures
Trigger A node is drained during maintenance, so the pod starts on another node with an empty index
Time after start What happens
0 s The pod starts and begins rebuilding its index.
10 s First liveness check: /health returns 503, index not ready.
20 s Second failure. Kubernetes kills the container and starts it again.
20 s The new container starts rebuilding from zero.
… The same thing, every 20 to 30 seconds, plus a growing delay between restarts.
Later The pod shows CrashLoopBackOff. The index is never more than a third built.

The service wasn’t stuck. It was making steady progress, and the probe destroyed the progress every time.

One probe was asked three different questions:

  • Has it finished starting? (startup)
  • Can it serve traffic right now? (readiness)
  • Is it stuck and in need of a restart? (liveness)

A slow start answers not yet to the first two and no to the third. Because the only probe was a liveness probe, every not ready yet was treated as stuck, and the remedy for stuck, a restart, is exactly what prevents a slow start from finishing.

Aspect Design A: one probe Design B: three probes, three questions
Startup No separate check A startup probe that allows, say, 30 × 10 s = 5 minutes. Kubernetes doesn’t run liveness or readiness checks until it succeeds
Readiness Combined with liveness A readiness probe on index ready. Failing removes the pod from traffic; it doesn’t restart it
Liveness /health: restart if not ready A liveness probe on the process is making progress: the index builder updates a progress counter, and liveness fails only if it hasn’t moved for 60 seconds
Slow but progressing pod Restarted forever Becomes ready after about 90 seconds
Genuinely stuck pod Restarted Still restarted, because progress stops
startupProbe: { httpGet: { path: /started, port: 8080 }, periodSeconds: 10, failureThreshold: 30 }
readinessProbe: { httpGet: { path: /ready, port: 8080 }, periodSeconds: 5 }
livenessProbe: { httpGet: { path: /progress, port: 8080 }, periodSeconds: 10, failureThreshold: 6 }

Test both halves; a design that never restarts anything passes the first and fails the second.

  1. A slow but progressing instance becomes ready. Start the service with a full-size index. Expected: no restarts; ready after about 90 seconds; traffic starts only then.
  2. A genuinely stuck instance still triggers recovery. Inject a hang that stops the index builder halfway. Expected: liveness fails after 60 seconds without progress, and the pod is restarted.

This check is in the checks catalog as test templates in Java and Python.

  • The service starts in a second or two, so not ready and stuck are never confused in practice.
  • The service has no slow warm-up, and readiness and liveness genuinely mean the same thing for it. Even then, a liveness probe that checks dependencies such as the database is a common way to restart every pod at once when the database blips.

Discussion question. Which failures should restart a process, and which should only take it out of traffic? Where does a failing database connection belong?

Exercise. The index grows by about 10% a month. In a year, the rebuild will take about 280 seconds, close to the startup probe’s 5-minute allowance. What will happen, and how would you stop it becoming next year’s incident?

Worked answer

Once startup takes longer than the allowance, the startup probe fails and the container is restarted: the original crash loop returns, triggered by data growth rather than a code change. Three defenses. Measure startup duration on every start and alert when it passes, say, 60% of the allowance, so the trend is visible months ahead. Base the startup check on progress, not a fixed time: fail only if the builder stops advancing. And remove the reason for slow starts: persist the index to a volume or fetch a prebuilt snapshot, so a restart resumes instead of starting from zero. The deeper lesson: any timeout tuned to today’s behavior is a future incident unless something watches the margin.

Written and edited by Abhinav Taduka, enterprise software architect.