Users see bursts of 502s every few hours; at the same time pods show `Last State: Terminated, Reason: OOMKilled, Exit Code: 137`.
IntermediateTroubleshooting5xx errors
Answer
Likely causes → The container exceeds its memory limit and the kernel kills it mid-request. Every in-flight request on that pod fails. Usual triggers: a leak, a large payload loaded fully into memory, or a limit set too low.
Diagnose →
kubectl get pods -n prod -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.containerStatuses[0].lastState.terminated.reason}{"\n"}{end}' | grep OOM
Graph container_memory_working_set_bytes against the limit: a steady climb means a leak, a sudden spike means a big request.
Fix → Raise the limit to stop the bleeding, then fix the leak or stream large payloads instead of buffering them.
Prevent → Alert when working set exceeds 85–90% of the limit, and load test with large payloads.
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.IntermediateEvery deploy causes 10–20 seconds of 502s from the ALB, even with a rolling update.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".Intermediate