Liveness vs Readiness vs Startup Probe in Kubernetes: Key Differences
liveness probe checks if a container is alive and restarts it if not, a readiness probe checks if a container is ready to serve traffic, and a startup probe ensures the container has started properly before other probes run. These probes help manage container health and availability efficiently.Quick Comparison
This table summarizes the main differences between liveness, readiness, and startup probes in Kubernetes.
| Probe Type | Purpose | Action on Failure | When It Runs | Typical Use Case |
|---|---|---|---|---|
| Liveness Probe | Checks if container is alive | Restarts container | Continuously after startup | Detects and recovers from deadlocks or crashes |
| Readiness Probe | Checks if container is ready to serve traffic | Removes pod from service endpoints | Continuously after startup | Controls traffic flow to container |
| Startup Probe | Checks if container startup is complete | Restarts container if startup fails | Only during container startup | Handles slow-starting containers |
Key Differences
Liveness probes monitor if a container is still running properly. If the probe fails, Kubernetes restarts the container to recover from issues like deadlocks or crashes. This probe runs continuously after the container starts.
Readiness probes check if a container is ready to accept requests. If it fails, Kubernetes stops sending traffic to that pod but does not restart it. This helps avoid sending requests to containers that are not fully initialized or temporarily busy.
Startup probes are designed for containers that take a long time to start. They run only during startup and prevent liveness probes from killing the container prematurely. If the startup probe fails, Kubernetes restarts the container, assuming it failed to start correctly.
Code Comparison
Example of a liveness probe configuration in a Kubernetes pod spec checking HTTP on port 8080:
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
failureThreshold: 3Readiness Probe Equivalent
Equivalent readiness probe configuration checking the same HTTP endpoint:
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
failureThreshold: 3When to Use Which
Use a startup probe when your container takes a long time to start and you want to avoid premature restarts by liveness probes.
Use a liveness probe to detect and recover from container crashes or deadlocks during normal operation.
Use a readiness probe to control when your container receives traffic, ensuring it only serves requests when fully ready.