liveBook · Manning

Liveness check

As explained in Kubernetes for Developers

A liveness probe is a Kubernetes health check that determines whether a running container is still functioning and should be allowed to continue running.

A container can still be running even when its process has hung or its service no longer responds. Kubernetes cannot recognize every application-specific failure on its own. A liveness check gives it a signal: when the check fails enough times, Kubernetes restarts the affected workload. section 4.1 section 4.1.3

Table 4.1 Differences between liveness and readiness (view table figure)

 

Liveness

Readiness

Semantic meaning

Is the container running?

Is the container ready to receive traffic?

Implication of probe failures exceeding threshold

Pod is terminated and replaced.

Pod is removed from receiving traffic until the probe passes.

Time to recover from a failed probe

Slow: Pod is rescheduled on failure and needs time to boot.

Fast: Pod is already running and can immediately receive traffic once the probe passes.

Default state at container boot

Passing (live).

Failing (unready).

Compare liveness with readiness before choosing what a failed check should mean: restart a failing workload, or temporarily stop sending it traffic. section 4.1.1

Keep the two decisions separate. A container waiting for a database may be unable to serve requests but still be functioning well enough to reconnect. Its readiness check should fail; its liveness check should normally keep passing. Because restarting takes time, tune liveness to be less hasty than readiness. section 4.1.1 section 4.1.4

Choose a check that demonstrates the container is making progress:

  • For an HTTP service, use a lightweight dedicated endpoint such as /healthz that returns HTTP 200 when server code responds. Configure it under livenessProbe in the Deployment; a basic example checks every 30 seconds and allows repeated failures before restarting. section 4.1.4 section 4.1.3
  • For a background worker without an HTTP or TCP endpoint, use a command-based probe. The worker can periodically write a timestamp, and the command can fail when that timestamp grows too old. section 10.4

When waiting becomes stuck

If a container remains unready because faulty retry logic never restores a connection, continually passing liveness checks will not restart it. One approach records the last successful readiness check and fails liveness only after prolonged unreadiness, giving the container time to recover first. section 4.1.5

How Kubernetes for Developers covers it

How deep it goes
Explains probe behavior, HTTP endpoint design, failure tolerance, and a command-based worker check, without exhaustively cataloging probe options.
Examples
Uses an HTTP health endpoint, a database-connection scenario, and a worker timestamp checked by a shell command.
What it assumes
Introduces Kubernetes health signals from running-container failure scenarios and explains liveness against readiness rather than assuming those probe semantics.
What you can do after
Operate/configure it with a Deployment livenessProbe and choose an HTTP or command check suited to the workload.
How it connects
Distinguishes liveness from readiness probes and relates it to Deployments, Services, external dependencies, and background Jobs.

Also explained in

Compare how 7 books explain liveness check →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.