Implementing Health Checks

1. Configuring Liveness Probes

Restart container if probe fails. Catches deadlocks where process is alive but stuck.

livenessProbe:
  httpGet: { path: /healthz, port: 8080 }
  initialDelaySeconds: 15
  periodSeconds: 10
  failureThreshold: 3
FieldDefault
initialDelaySeconds0
periodSeconds10
timeoutSeconds1
failureThreshold3
successThreshold1 (always for liveness)

2. Configuring Readiness Probes

Remove pod from Service endpoints when failing. No restart; lets pod warm up or shed load.

readinessProbe:
  httpGet: { path: /ready, port: 8080 }
  periodSeconds: 5
  failureThreshold: 3
  successThreshold: 1
Use CasePattern
Cache warmupReturn 503 until cache loaded
DB connectionProbe fails until DB pool ready
Graceful shutdownSet unready before SIGTERM

3. Configuring Startup Probes

Disables liveness/readiness until startup succeeds. Lets slow-starting apps avoid premature restarts.

startupProbe:
  httpGet: { path: /healthz, port: 8080 }
  failureThreshold: 30   # 30 * 10s = 5 min max startup
  periodSeconds: 10
PropertyNote
Runs onceUntil first success; then liveness/readiness take over
Best forJVMs, legacy apps with long init

4. Using HTTP Probes

FieldUse
pathHTTP path
portNumber or named port
schemeHTTP (default) or HTTPS
httpHeadersCustom headers (e.g. Host)
Success codes200-399

5. Using TCP Probes

readinessProbe:
  tcpSocket: { port: 5432 }
  periodSeconds: 5
UseCaveat
DB/queue connectivityOnly checks TCP accept; doesn't validate app health

6. Using Exec Probes

livenessProbe:
  exec: { command: ["pg_isready","-U","app"] }
  periodSeconds: 10
ResultOutcome
exit 0Healthy
non-zeroUnhealthy
timeoutUnhealthy (kills process)
Warning: Exec probes fork a process every period; expensive at scale.

7. Using gRPC Probes

livenessProbe:
  grpc: { port: 9000, service: "" }   # empty = overall server
RequirementDetail
App supportImplement grpc.health.v1.Health
StableSince v1.27

8. Setting Initial Delay

ProbeTypical initialDelaySeconds
Fast service5
JVM/Node app15-30
Slow startupUse startupProbe instead

9. Configuring Period Seconds

Probe TypeTypical periodSeconds
Liveness10-30 (avoid CPU overhead)
Readiness5-10 (fast feedback for LB)
Startup5-10 with high failureThreshold

10. Setting Failure Threshold

ProbeEffect of Reaching Threshold
LivenessRestart container
ReadinessRemove from Service endpoints
StartupRestart container (init failed)

11. Setting Success Threshold

ProbeAllowed Values
Liveness / StartupMust be 1
Readiness≥1; require N consecutive successes after failure

12. Configuring Timeout Seconds

PropertyNote
Default1s (often too tight)
Recommendation≥3s for HTTP; ≥5s for exec
TipProbe timeout should be < periodSeconds

Probe Cheat Sheet

  • Liveness = "restart me when broken" — use sparingly
  • Readiness = "stop sending traffic" — essential for rolling updates
  • Startup = "wait before judging" — for slow boots
  • Never probe external dependencies in liveness (cascading restarts)