Skip to content

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.
  1. Endpoints: kubectl get endpointslices -n <ns> -l kubernetes.io/service-name=<svc> -o wide. Empty means 503: see No endpoints.
  2. Port: the Ingress or route’s backend port must be a port the Service exposes, and the Service’s targetPort must be where the container listens.
  3. 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.
  4. Controller logs: the proxy’s error log names the upstream address and the failure (connection refused, upstream prematurely closed connection, no live upstreams).
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.