Liveness and Readiness Probes

Introduction: When "Running" Isn't Enough

Imagine you've deployed your web application to production. You check kubectl get pods and see STATUS: Running for all your containers. Everything looks perfect, so you go home for the evening. But at 2 AM, you get paged because users are reporting error messages and timeouts. You check again — the pods still show as Running. What's going on? A container can be technically running but completely nonfunctional. Maybe the application deadlocked while processing a request.

Maybe it ran out of database connections and can't serve traffic anymore. The pod status only tells Kubernetes that the process is alive, not whether it's actually healthy. In this lesson, you'll learn how health probes enable Kubernetes to automatically detect these problems and take corrective action, whether that means restarting the container or temporarily stopping traffic until it recovers.

Understanding Health Probe Types

Kubernetes actually provides three different types of health probes, though we'll focus on two in this lesson. Understanding when to use each probe is crucial for building reliable systems. A liveness probe answers the question: "Is this container alive and functioning?" Think of it as checking for a pulse. If the liveness probe fails repeatedly, Kubernetes assumes the container is in a broken state that it cannot recover from on its own. The kubelet (the Kubernetes agent on the node) will kill the container and restart it, hoping that a fresh start will fix the problem. This is perfect for situations like application deadlocks, infinite loops, or corrupted internal states where the only solution is to restart the process.

A readiness probe answers a different question: "Is this container ready to receive traffic right now?" This probe doesn't indicate whether the container is broken — it indicates whether it's currently capable of handling requests. If the readiness probe fails, Kubernetes removes the pod's IP address from any Service endpoints, ensuring that no new traffic gets routed to it. The container keeps running, and Kubernetes keeps checking the readiness probe. Once the probe starts succeeding again, the pod is added back to the Service and begins receiving traffic. This is ideal for temporary conditions like loading large datasets into memory, waiting for database connections to be established, or performing cache warm-up operations.

The third type, a startup probe, is specifically designed for applications with slow startup times. It runs only during container initialization, and while it's running, the liveness and readiness probes are disabled. Once the startup probe succeeds, it stops running and the liveness and readiness probes take over. This prevents situations where a liveness probe kills a container that's still legitimately starting up. For most applications, configuring appropriate initialDelaySeconds on your liveness probe is sufficient, but startup probes are valuable when startup time is highly variable or exceptionally long.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal