Interview Prep/Kubernetes/Resources, OOM, probes and termination

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.

All Kubernetes questions Roadmap: Kubernetes core

More on Resources, OOM, probes and termination