Ingress returns 502 or 503
The request reached your ingress controller or gateway, matched a rule, and failed on the way to the backend.
- 503 Service Unavailable usually means the backend Service has no Ready endpoints.
- 502 Bad Gateway usually means the proxy reached a pod but the connection failed or the response was invalid.
- 504 Gateway Timeout means the backend accepted the connection but didn’t answer in time.
Diagnose in order
Section titled “Diagnose in order”- Endpoints:
kubectl get endpointslices -n <ns> -l kubernetes.io/service-name=<svc> -o wide. Empty means 503: see No endpoints. - Port: the Ingress or route’s backend port must be a port the Service exposes, and the Service’s
targetPortmust be where the container listens. - Protocol: if the app serves HTTPS and the proxy sends HTTP (or the reverse), you get 502s. Most controllers need an annotation or a backend policy to speak HTTPS to backends.
- Controller logs: the proxy’s error log names the upstream address and the failure (
connection refused,upstream prematurely closed connection,no live upstreams).
Usual causes
Section titled “Usual causes”| Status | Cause |
|---|---|
| 503 | No Ready pods, or the Service name in the rule is wrong |
| 502 | Wrong port, protocol mismatch, app crashing mid-request, or the app closing keep-alive connections before the proxy does |
| 504 | Slow backend, or a proxy timeout shorter than the request needs |
Fix the first layer that fails, in the order above. For intermittent 502s under load, compare the app’s keep-alive timeout with the proxy’s; the app’s must be longer.
Read next: Ingress and Gateway API.