Health Checks: Liveness and Readiness Probes
What you'll learn: How to configure Kubernetes probes so the orchestrator knows when to restart unhealthy containers or when pods are ready to receive traffic.
The Problem
Your application is running in a pod, but how does Kubernetes know if it's actually working? A container process might be running but stuck in a deadlock, or your application might still be loading configuration files. Without health checks, Kubernetes would route traffic to broken pods or leave crashed containers running indefinitely.
Two Types of Probes
Liveness Probes answer: "Is this container alive and healthy?"
If a liveness probe fails repeatedly, Kubernetes restarts the container. Think of this as a heartbeat monitor—if your application enters an unrecoverable state (deadlock, memory corruption), the liveness probe catches it and triggers a restart.
Readiness Probes answer: "Is this pod ready to accept traffic?"
If a readiness probe fails, Kubernetes removes the pod from the service's load balancer but doesn't restart it. This is crucial during startup (loading data, warming caches) or temporary overload—your app is alive, just not ready to serve requests yet.
How They Work
Each probe type can use three mechanisms:
- HTTP GET: Send a request to a specific endpoint (e.g.,
/healthz) - TCP Socket: Attempt to open a connection on a port
- Exec Command: Run a command inside the container and check its exit code
You configure timing parameters like initial delay (how long to wait before first check), period (how often to check), and failure threshold (how many failures before action).
Why Both Matter
Without liveness probes, crashed applications sit idle. Without readiness probes, traffic hits pods that aren't ready, causing errors. Together, they ensure Kubernetes automatically maintains healthy, traffic-ready pods.
Key Takeaway:
Liveness probes restart unhealthy containers; readiness probes control traffic routing—configure both to let Kubernetes automatically manage pod health and availability.