Nginx ingress was returning 502 Bad Gateway for every request. The pod was Running, the Ingress resource looked fine, and kubectl describe ingress showed no obvious errors.
Root cause:
The Service was pointing port: 8080 → targetPort: 8080, but the Node.js app inside the container was actually listening on port 3000. Nginx couldn't reach the backend, so it returned 502.
Fix:
First, verify what port the app is really on:
kubectl exec -it <pod-name> -- curl localhost:3000Then fix the Service spec:
# service.yaml — corrected targetPort
spec:
ports:
- port: 80
targetPort: 3000 # was 8080 — must match EXPOSE in Dockerfile
selector:
app: my-appApply and test:
kubectl apply -f service.yaml
kubectl exec -it <pod-name> -- curl http://my-service.default.svc.cluster.localLesson: 502 from Nginx almost always means the Service can't reach the pod — check targetPort matches the actual port the app listens on, not just what's in the Dockerfile EXPOSE.