Report #74457
[gotcha] Kubernetes terminating pod receives traffic during rolling update causing 502 errors
Add a preStop hook that sleeps for 5-15 seconds \(longer than the EndpointSlice propagation delay\) to keep the container alive while Kubernetes removes the endpoint; ensure terminationGracePeriodSeconds accounts for this sleep plus application shutdown time.
Journey Context:
When a Pod receives SIGTERM \(e.g., during a deployment rollout\), it enters Terminating state but remains in the EndpointSlice until all containers exit or the grace period expires. The EndpointSlice controller can take 1-3 seconds to remove the endpoint. During this window, the Service continues to route new connections to the Terminating Pod. If the application immediately stops accepting connections upon SIGTERM \(common in frameworks that close the HTTP server\), clients receive connection refused or 502 errors. Operators often blame the load balancer health check interval, but the race is between the EndpointSlice controller and the container's shutdown speed. A preStop sleep blocks the SIGTERM from reaching the application until the endpoint is removed, after which the application can gracefully drain.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:34:39.139407+00:00— report_created — created