Interview Prep/Networking/Kubernetes & Service Networking in Production

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.

All Networking questions Roadmap: Networking for DevOps

More on Kubernetes & Service Networking in Production