Cloud Computing

Kubernetes liveness probe kills Spring Boot JVM pod during G1 GC pauses — pods restart under moderate load

viggovpn
1mo ago
Environment

Environment

Kubernetes 1.24 on managed cluster, Spring Boot 2.7 (OpenJDK 11) microservice, container resources requests 500m/512Mi and limits 1 CPU/1Gi, liveness probe HTTP /actuator/health with timeoutSeconds:1, periodSeconds:10, failureThreshold:3.

Symptoms

Symptoms

Pods restarted during normal traffic bursts. Application logs show occasional 1.2–2.5s stop-the-world G1 GC pauses and thread-dump timestamps correlate to liveness probe failures. After restart readiness passes but pod is later killed again.

Observations

Observations

Heap is ~70% at bursts and CPU throttling events in kubelet metrics correlate with GC duration spikes. Increasing liveness timeout to 2s reduced restarts but did not eliminate them. Readiness probe was not used to gate traffic before GC events. No deadlock traces present.

Already attempted

Already attempted

Raised liveness timeout to 2s, temporarily set failureThreshold to 5, increased CPU request to 700m for one deployment (pod restarts less frequent), added -XX:MaxGCPauseMillis=200 and -XX:+UseG1GC (already default).

Question

Question

Best practice probe and JVM tuning to avoid false liveness kills during GC? How to tune without overprovisioning resources?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Liveness probe timeout too low relative to transient stop-the-world GC pauses 90%
CPU throttling due to low resource requests causing longer GC pauses 55%
Blocking/expensive work performed inside the /health endpoint causing additional delays 40%

Summary

Primary cause: liveness probe too strict relative to JVM stop-the-world GC pauses and occasional CPU throttling; the probe times out while GC pauses block the health endpoint, so Kubernetes perceives an unhealthy pod. Evidence: GC durations exceed probe timeout and raising CPU requests reduced frequency. Secondary causes include insufficient CPU share leading to throttling under bursty load and synchronous health-check code path that blocks during GC. Solutions combine probe tuning, JVM GC tuning, and resource sizing. Implementing readiness probe semantics and making the health endpoint lightweight/async reduces false positives.

Suggested Fixes

Diagnostic step 1
Replace the liveness probe with a lightweight, non-blocking endpoint (e.g., /health/liveness that returns 200 immediately) and use a separate readiness probe for deeper checks.
Diagnostic step 2
Increase liveness timeoutSeconds to at least 3s and failureThreshold to 5 during rollout; measure impact before fine-tuning downwards.
Diagnostic step 3
Adjust JVM and container resources: raise CPU request to avoid throttling and set -XX:MaxGCPauseMillis=200; test with load to validate GC pause distribution.

Continue troubleshooting

Matched from the title, description and tags