How do you achieve graceful pod shutdown with no dropped requests?
AdvancedProductionKubernetes & Service Networking in Production
Answer
Kubernetes removes the pod from endpoints and sends SIGTERM concurrently, so load balancers may still send traffic for several seconds. Add a preStop sleep of 5–15s, handle SIGTERM by stopping new accepts and finishing in-flight work, and set terminationGracePeriodSeconds above both.
lifecycle:
preStop:
exec: {command: ["sleep", "10"]}
terminationGracePeriodSeconds: 45
With ALB IP targets, deregistration delay must also be accounted for.
More on Kubernetes & Service Networking in Production
How do you expose an application on Kubernetes to the internet in production?BeginnerALB IP mode versus instance mode on EKS: which should you use?IntermediateHow do readiness, liveness and startup probes interact with traffic?BeginnerHow do you design default-deny NetworkPolicies without breaking DNS?IntermediateHow do you debug "pod cannot reach service" in Kubernetes?AdvancedHow do you scale CoreDNS and avoid DNS becoming an outage source?Advanced