A `preStop` hook with `sleep 20` makes Pods take 50 seconds to terminate and sometimes they get SIGKILL mid-request.
IntermediateTroubleshootingResources, OOM, probes and termination
Answer
Likely causes → terminationGracePeriodSeconds covers both the preStop hook and the app's shutdown. With the default 30s, a 20s sleep leaves only 10s for draining. If the app needs more, it is killed. Events may show FailedPreStopHook or Exceeded grace period.
Diagnose →
kubectl get deploy web -o jsonpath='{.spec.template.spec.terminationGracePeriodSeconds} {.spec.template.spec.containers[0].lifecycle}'
Fix → Make the grace period larger than preStop plus shutdown:
terminationGracePeriodSeconds: 60
containers:
- name: app
lifecycle:
preStop:
sleep: {seconds: 15} # native sleep action, no shell needed (1.30+ beta, GA 1.34)
Prevent → Measure real drain time per service and budget the grace period from it.
More on Resources, OOM, probes and termination
`kubectl describe pod` shows `Last State: Terminated, Reason: OOMKilled, Exit Code: 137`.BeginnerA Java service is OOMKilled at 2 GiB limit but the heap is only `-Xmx1800m`.IntermediateMany Pods on one node were killed at once and the node shows a `SystemOOM` event. Container limits were not reached.AdvancedPods show `Evicted` with `The node was low on resource: memory. Threshold quantity: 100Mi, available: 87Mi. Container app was using 1.4Gi, request is 256Mi`.IntermediateA Pod is evicted with `Pod ephemeral local storage usage exceeds the total limit of containers 1Gi`.Intermediatep99 latency spikes every few seconds, CPU usage graph shows only 40% of the limit.Advanced