Video in progress
The Kubernetes liveness probe is killing Java pods during long GC pauses or warm-up. How do you configure the probes?
Liveness should answer only "is the process in an unrecoverable state", not "is it slow". I point it at a lightweight endpoint with no external dependencies, set the timeout and failureThreshold well above the worst pause in the GC log, and use a startupProbe for warm-up.
📖 Answer
The classic chain: a Full GC takes 4 seconds → liveness with timeoutSeconds: 1 fails three times → the kubelet kills the pod → the load shifts to the remaining pods → they go into GC too → a cascade of restarts. Or: a new pod answers slowly during JIT warm-up and is killed before it has finished starting.
This is how I configure it:
startupProbe: # for warm-up and the Spring context
httpGet: { path: /actuator/health/liveness, port: 8080 }
periodSeconds: 5
failureThreshold: 36 # up to 3 minutes
livenessProbe:
httpGet: { path: /actuator/health/liveness, port: 8080 }
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6 # ~1 minute of constant non-response
readinessProbe:
httpGet: { path: /actuator/health/readiness, port: 8080 }
periodSeconds: 5
failureThreshold: 2
A few rules:
- Keep DB, Redis and external API checks out of liveness. If the DB slows down, all the pods get killed at the same time. That is not a fix, it is an incident. In Spring Boot 3 the
livenessandreadinessgroups are separate, and liveness by default looks only at the application's own state. - Take the numbers from the GC log. If the worst pause you've seen is 3 s, make the liveness window several times bigger.
- Let readiness react faster. If a pod is slow, taking it out of traffic is better than a restart.
- Put the probe endpoint on a separate thread pool. If all of Tomcat's threads are busy, the probe waits in the queue too. Putting the management port on its own (
management.server.port) helps.
One more thing: loosening the probes is not meant to hide a GC problem. A 4-second Full GC still has to be fixed. The probe settings are only there so that it doesn't turn into a cascade.
Sign up to mark studied questions and save your progress.