After a deploy, pods are Ready but users get 502s for a few seconds. What is happening and how do you fix it?
IntermediateScenarioDeployments and rollouts
Answer
Situation read → Old pods are removed from endpoints and killed while the ingress or load balancer still sends traffic to them.
What I'd do →
- Add a
preStophook withsleep 10(or uselifecycle.preStop.sleep.secondson recent versions) - Make the app handle SIGTERM: stop accepting new connections, finish in-flight requests
- Set
terminationGracePeriodSecondslarger than preStop plus drain time - Check ingress controller and ALB deregistration delay are not longer than the grace period
- Test with
heyork6during a rollout
Why → Endpoint removal and SIGTERM happen in parallel. Proxies and load balancers update asynchronously, so the pod must keep serving briefly after it is told to stop.
Interview tip → This is a classic question; the key phrase is "endpoint propagation races SIGTERM".
More on Deployments and rollouts
You applied a new image tag and the rollout seems stuck at "1 out of 3 new replicas have been updated". What do you check first?BeginnerHow do you roll back a bad release and verify you are back on the previous version?BeginnerA rollout must never reduce capacity below current replicas. How do you configure the strategy?IntermediateYou need a blue/green deployment without a service mesh. How do you do it with plain Kubernetes?IntermediateHow would you do a canary release with only Deployments and a Service?IntermediateWhat is the difference between Recreate and RollingUpdate strategies and when would you pick Recreate?Beginner