When users encounter 502 Bad Gateway and 503 Service Unavailable errors on a frontend application, panic often sets in. However, a systematic approach can quickly isolate the root cause.

A common starting point for incident triage is verifying cluster health—such as confirming that nodes and cluster memory are fully stable with no resource exhaustion. When infrastructure resources are healthy, the issue usually points directly to networking configurations, routing paths, API URL mappings, or backend application pods.

Understanding the Difference: 502 vs. 503

Before diving into commands, it helps to understand what the gateway or ingress controller is telling you:

Step-by-Step Troubleshooting Guide

Step 1: Verify Cluster and Node Resources

As noted during initial triage, rule out infrastructure-level bottlenecks first:

Step 2: Check Service Endpoints (Diagnosing 503 Errors)

If you are seeing 503 errors, your ingress controller cannot find active pods to hand traffic to.

Bash

kubectl get endpoints <your-backend-service-name>

Step 3: Inspect Ingress Controller Logs (Diagnosing 502 Errors)

If you are seeing 502 errors, the request is hitting a backend pod, but failing during communication. Inspect the ingress controller logs (e.g., NGINX Ingress) to see what error the proxy returned:

Bash

kubectl logs -n ingress-nginx -l app.kubernetes.io/component=controller --tail=100

Step 4: Validate API URLs and Routing Configurations

When frontend applications throw these errors unpredictably, configuration drift in API routes is a frequent culprit:

Summary Checklist for the Team

  1. Confirm cluster node metrics and memory status are normal.

  2. Run kubectl get endpoints to check if backend services have active targets.

  3. Review Ingress controller logs to pinpoint whether it's a 502 (bad upstream response) or 503 (no upstreams found).

  4. Double-check frontend environment variables and API URL configurations.