Kubernetes interview question · Most asked

How do you make pods shut down gracefully without dropping requests?

Summary

When a pod is deleted, Kubernetes marks it terminating, removes it from Service endpoints, runs any preStop hook, sends SIGTERM to the containers and, after terminationGracePeriodSeconds (30 by default), SIGKILL. Endpoint removal and SIGTERM happen in parallel, so the app must keep serving briefly after SIGTERM, finish in-flight requests, then exit.

Longer Answer

Checklist: the application handles SIGTERM (stops accepting new work, drains in-flight requests and background jobs, closes connections); the process actually receives the signal (exec-form ENTRYPOINT, an init such as tini if needed, not a shell that swallows it); a short preStop sleep (a few seconds) covers the delay before load balancers and kube-proxy stop sending traffic; and the grace period is long enough for the longest request or job.

Without this, every deploy, scale-in and node drain produces a burst of 502s.

Key Points

  • Endpoint removal and SIGTERM race.
  • Handle SIGTERM: drain, then exit.
  • preStop sleep for load balancer lag.
  • Grace period >= longest request.

More most-asked Kubernetes questions

← All Kubernetes questions