Video in progress
How do you configure liveness, readiness and startup probes for a Spring Boot service in Kubernetes?
Liveness only answers "has the process entered an unrecoverable state?" and doesn't check external dependencies. Readiness asks "can I take traffic right now?". The startup probe is for slow starts. I use Actuator's /actuator/health/liveness and /readiness groups and choose carefully which indicator goes into which group.
📖 Answer
management:
endpoint:
health:
probes:
enabled: true
group:
readiness:
include: readinessState, db
server:
port: 8081
startupProbe:
httpGet: { path: /actuator/health/liveness, port: 8081 }
periodSeconds: 5
failureThreshold: 30 # up to 150 s to start
livenessProbe:
httpGet: { path: /actuator/health/liveness, port: 8081 }
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet: { path: /actuator/health/readiness, port: 8081 }
periodSeconds: 5
The most dangerous mistake is putting the database into liveness. If the database is down for 30 seconds, Kubernetes kills all the pods and restarts them. The restarting pods all try to connect to the database at once, which makes its recovery harder again. A small problem turns into a full outage.
Be careful when adding dependencies to readiness too: if a shared database goes down, every pod becomes not ready and the service returns 503. Sometimes that's right, and sometimes it's better to keep running in degraded mode (say, reading from a cache).
Also: keep the probes on a separate management port, so congestion in the main pool doesn't block them; set the probe timeout so it tolerates long GC pauses; and on graceful shutdown, readiness switches to REFUSING_TRAFFIC by itself.
Sign up to mark studied questions and save your progress.