Back to 20 Concepts
k8s-coreIntermediate

Kubernetes Pod Lifecycle & Health Probes (Liveness vs Readiness)

A Pod is the smallest deployable compute unit in Kubernetes (sharing network IP and storage volumes). Health probes determine if containers should be restarted (Liveness), receive traffic (Readiness), or given time to boot (Startup).

Intuitive Mental Model

The Restaurant Chef: Startup Probe checks if the chef has arrived at work; Readiness Probe checks if the chef has prepped ingredients and is ready to take customer orders; Liveness Probe checks if the chef has fainted and needs replacement.

Dockerfile / YAML Manifest / CLIProduction Standard
apiVersion: v1
kind: Pod
metadata:
  name: web-pod
spec:
  containers:
  - name: app
    image: web:v1
    # 1. Startup Probe: Grants up to 60s for initial database migrations:
    startupProbe:
      httpGet:
        path: /health/startup
        port: 8080
      failureThreshold: 30
      periodSeconds: 2
    # 2. Readiness Probe: Controls inclusion in Service endpoint pool:
    readinessProbe:
      httpGet:
        path: /health/ready
        port: 8080
      periodSeconds: 5
    # 3. Liveness Probe: Restarts container on deadlocks:
    livenessProbe:
      httpGet:
        path: /health/live
        port: 8080
      periodSeconds: 10

Key Architectural Takeaways

  • Readiness Probe Failure: Removes Pod IP from Service Endpoints (stops routing traffic), but does NOT restart the container.
  • Liveness Probe Failure: Kubelet immediately kills and restarts the container based on restartPolicy.
  • CrashLoopBackOff: Occurs when a container exits immediately on startup (Exit Code 1 or 137), triggering exponential restart backoff (10s, 20s, 40s... up to 5min).
Common Production Mistake

Checking external database dependencies in a Liveness Probe; if the DB has a blip, ALL Pods in the cluster restart simultaneously, causing a cascading outage.

Recommended Solution

Check external dependencies only in Readiness Probes; keep Liveness Probes strictly checking internal process deadlocks.