Interview Prep/Kubernetes/Deployments and rollouts

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 →

  1. Add a preStop hook with sleep 10 (or use lifecycle.preStop.sleep.seconds on recent versions)
  2. Make the app handle SIGTERM: stop accepting new connections, finish in-flight requests
  3. Set terminationGracePeriodSeconds larger than preStop plus drain time
  4. Check ingress controller and ALB deregistration delay are not longer than the grace period
  5. Test with hey or k6 during 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".

All Kubernetes questions Roadmap: Kubernetes core

More on Deployments and rollouts