With AWS ECS, when a service scales in or deploys, ECS first deregisters the task from the Application Load Balancer and lets existing requests drain before sending SIGTERM to the container. This prevents in-flight requests from being cut off and avoids unexpected 5xx responses.
I may need to migrate to Amazon EKS, and the Kubernetes termination process seems less straightforward. It appears that a pod can receive its termination signal while the service or load balancer is removing it from rotation. Many examples recommend using a lifecycle preStop hook that sleeps for a few seconds, but occasional 5xx responses can still occur.
Does EKS provide a reliable graceful-shutdown mechanism for this? Is using readiness probes, endpoint removal, load-balancer draining, and a preStop delay the normal Kubernetes approach, or is there a better way to ensure in-flight requests finish before a pod is stopped?
3 Answers
Kubernetes does support this, but it is a coordinated shutdown rather than an instant container stop. When a pod begins terminating, it is marked for removal from the Service endpoints, which causes new traffic to stop being routed there. The pod then runs its termination lifecycle, including any preStop hook, receives SIGTERM, and is eventually force-killed when terminationGracePeriodSeconds expires.
In practice, configure the application to stop accepting new work after SIGTERM, give existing requests enough time to finish, and set an appropriate termination grace period. A short preStop delay is often used to give endpoint and load-balancer state time to propagate, but it should be treated as a safety margin rather than the main draining mechanism.
This is not unique to EKS. Older load balancers and other orchestrators have always needed a window between taking an instance out of rotation and stopping its process. Kubernetes generally follows the same pattern, but propagation is asynchronous, so a small race is possible.
Use a sufficiently long terminationGracePeriodSeconds, configure the load balancer's deregistration timeout, and test rolling updates and scale-in under real traffic. If occasional 5xx responses remain, check whether they come from the load balancer, the application closing connections, or the client timing out; those point to different fixes.
For EKS, the exact behavior also depends on how the load balancer integrates with Kubernetes. Readiness gates, endpoint removal, target registration mode, and the load balancer's deregistration delay all matter. Make sure the pod is not considered ready once shutdown starts, and verify that the load balancer waits for existing connections to drain.
Also make sure the application handles SIGTERM correctly. If it exits immediately, no amount of load-balancer configuration can protect requests that are already being processed.

Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures