Course map

Topic 183 / Advanced

Health probes and resource management

Chapter 11.3 · Kubernetes

What and why

The control plane (→ 181) can only reconcile toward "healthy" if something tells it what healthy means for a given Pod, and it can only schedule and isolate workloads correctly (→ 182) if it knows how much CPU and memory each one needs. Health probes and resource requests/limits are how a Pod declares both. Builds on: → 182 (Kubernetes workloads, networking and storage).

Diagram

Probe Question it answers Wrong probe's failure mode
Startup has the app finished initializing? liveness kills a still-starting app
Readiness can the app serve traffic right now? traffic sent to an app that's up but can't serve — errors
Liveness is the app alive, or stuck and needing a restart? a slow-but-healthy app is killed and restart-looped

How it works

  1. A startup probe gives a slow-initializing application time to finish starting before liveness/readiness checks begin judging it — without one, a liveness probe can kill an app that was simply still starting.
  2. A readiness probe tells the Service (→ 182) whether this Pod should currently receive traffic; failing readiness removes the Pod from routing without restarting it — this is what makes graceful shutdown (→ 98) and gradual rollout work: a Pod that's shutting down or not yet warmed up simply stops receiving new requests.
  3. A liveness probe tells the control plane whether this Pod needs to be killed and restarted because it's stuck. It should check only "is the process able to respond at all," never a downstream dependency — or one dependency outage restarts every Pod that depends on it, often making the outage worse, not better.
  4. Resource requests tell the scheduler the minimum a Pod needs — it only places a Pod on a node with enough unreserved capacity to meet its requests, which is what prevents over-packing a node past what it can actually deliver.
  5. Resource limits cap what a Pod may use even if more is available — exceeding a memory limit gets a Pod killed; exceeding a CPU limit gets it throttled, not killed, since CPU is a compressible resource.
  6. A pod disruption budget bounds how many Pods of a set may be voluntarily down at once during a node drain or maintenance — protecting a workload that can't tolerate even a momentary drop in replica count.
  7. Horizontal pod autoscaling (→ 95) reads a metric — often CPU against requests — and adjusts replica count; it depends entirely on requests being set honestly, since unset or wrong requests make autoscaling decisions meaningless.

Practical example

(numbers illustrative). A service's liveness probe is wired to check its database connection. The database has a brief outage. Every Pod of the service fails its liveness check simultaneously, is killed and restarted, and comes back up only to immediately fail the same check again — one downstream outage is amplified into a full restart loop of an otherwise-healthy service. Rewiring liveness to check only "is this process responsive," and leaving the database check to readiness (which stops new traffic rather than restarting the process), removes the amplification: the service degrades gracefully and recovers the instant the database does, with no restart storm.

When to use it

  • Use readiness for anything that affects whether this Pod should get traffic right now; use liveness only for "this process is unrecoverably stuck," never for a downstream dependency.
  • Use resource requests set from measured usage (→ 103), not guesses — both over-requesting (wasted capacity, fewer Pods per node) and under-requesting (node over-commitment, noisy-neighbor contention) cause real problems.
  • Avoid a liveness probe with the same check as readiness — it couples "stop sending traffic" with "kill and restart," removing the graceful-degradation option entirely.
  • Failure scenarios: the database-outage restart storm above; a missing startup probe killing a slow-starting app in a crash-restart loop before it ever finishes initializing; unset resource requests letting the scheduler pack a node past what it can deliver under real load, degrading unrelated Pods on that node.
  • Simpler alternative: for a simple, fast-starting stateless app with no slow dependency on startup, a basic HTTP readiness check plus a liveness check on process responsiveness alone is enough — the startup/liveness distinction matters most for apps with real startup cost or flaky dependencies.

Practice

(trace/predict kind, 20 min, conceptual — no cluster required). Given a Pod spec with liveness checking a downstream database and readiness unset, predict what happens during a 2-minute database outage; then redesign the probes (liveness on process health only, readiness on the database) and predict the same scenario again. Done when the second prediction shows no restart and the first does.

Key takeaway

Readiness controls traffic, liveness controls restarts, and conflating them turns a downstream outage into a self-inflicted restart storm; resource requests and limits are what make scheduling and autoscaling trustworthy instead of guesswork. Done when you can: design probes that fail safely for a given dependency graph, and set requests from measured usage rather than a guess. Used next in → 187 (readiness gates every rolling/canary deployment's traffic shift), Part 12 (→ 192 — the same health signal becomes an availability input).

References

Kubernetes: Concepts — see references.md.

Source directory

Search the guide