Every deploy causes 10–20 seconds of 502s from the ALB, even with a rolling update.
IntermediateTroubleshooting5xx errors
Answer
Likely causes → Kubernetes sends SIGTERM and removes the endpoint at the same time, but the ALB (via the AWS Load Balancer Controller) takes several seconds to deregister the target. Meanwhile the app has already exited, so in-flight and new requests hit a dead pod.
Diagnose → ALB access logs during the deploy show 502 with target_status_code=- for pods that were terminating.
Fix →
lifecycle:
preStop:
exec: { command: ["sleep", "20"] }
terminationGracePeriodSeconds: 45
Also make the app drain on SIGTERM, and tune the target group's deregistration_delay.timeout_seconds.
Prevent → Enable pod readiness gates with the AWS Load Balancer Controller so new pods receive traffic only after the ALB marks them healthy, and run a load test during a deploy in staging.
More on 5xx errors
Right after a release, 500s spike to 8% and logs show `java.lang.NullPointerException` in a new code path.BeginnerLong-running report exports fail with "504 Gateway Time-out" from the ALB at exactly 60 seconds.Beginnernginx logs "upstream prematurely closed connection while reading response header from upstream" and users get 502.IntermediateA Node.js service behind an ALB returns a steady trickle of 502s under normal load, with no app errors at all.AdvancedThrough Istio, clients get "503 upstream connect error or disconnect/reset before headers. reset reason: connection failure".IntermediateAPI Gateway returns "502 Bad Gateway" and the logs say "Execution failed due to configuration error: Malformed Lambda proxy response".Beginner