0
0
KubernetesComparisonBeginner · 3 min read

Liveness vs Readiness vs Startup Probe in Kubernetes: Key Differences

In Kubernetes, a 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 TypePurposeAction on FailureWhen It RunsTypical Use Case
Liveness ProbeChecks if container is aliveRestarts containerContinuously after startupDetects and recovers from deadlocks or crashes
Readiness ProbeChecks if container is ready to serve trafficRemoves pod from service endpointsContinuously after startupControls traffic flow to container
Startup ProbeChecks if container startup is completeRestarts container if startup failsOnly during container startupHandles 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:

yaml
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 10
  periodSeconds: 5
  failureThreshold: 3
↔️

Readiness Probe Equivalent

Equivalent readiness probe configuration checking the same HTTP endpoint:

yaml
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  initialDelaySeconds: 5
  periodSeconds: 5
  failureThreshold: 3
🎯

When 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.

Key Takeaways

Liveness probes restart containers that are unhealthy or stuck.
Readiness probes control traffic flow by marking containers ready or not.
Startup probes prevent premature restarts during slow container startup.
Use startup probes for slow-starting apps, liveness for crash recovery, readiness for traffic control.