CodePark/ questions / Orchestration & Kubernetes basics
START PRACTICINGPRACTICE
Backend question · Docker › Orchestration & Kubernetes basics

What is the difference between liveness, readiness and startup probes in Kubernetes?

Each probe asks a different question, and a failure causes a different action.

A liveness probe asks: "Is the container still working?" If it fails enough times, the kubelet kills the container and restarts it. The kubelet is the Kubernetes agent that runs containers on each node. Use liveness to recover from deadlocks or a hung event loop.

A readiness probe asks: "Can the container serve traffic right now?" If it fails, Kubernetes removes the Pod from the Service's endpoints. Endpoints are the list of Pods that a Service sends traffic to. The Pod is not restarted. Use readiness:

  • during warm-up
  • while waiting for dependencies
  • when the app is overloaded

A startup probe is for apps that start slowly. Until it succeeds, Kubernetes turns off the liveness and readiness checks. This way, a long startup is not mistaken for a hang.

For a Node API, a typical setup is:

  • a cheap /healthz endpoint for liveness
  • a /ready endpoint for readiness. It returns 503 until the app has finished starting, and again during shutdown.
  • A liveness failure restarts the container.
  • A readiness failure removes the Pod from the Service's endpoints, so it gets no traffic.
  • A readiness failure does not restart the container.
  • A startup probe pauses the other probes until a slow app has started.