Run these commands inside the pod to diagnose the 502 Bad Gateway issue.
# 1. Check if the backend process is running
ps aux | grep cased-backendExpected output: Should show /app/cased-backend process running
# 2. Test backend directly (should return "OK")
curl -v http://127.0.0.1:8081/healthExpected output: OK
# 3. Check what port the backend is listening on
netstat -tlnp | grep 8081Expected output: Should show 0.0.0.0:8081 or 127.0.0.1:8081
# 4. Check nginx error logs for more details
tail -50 /var/log/nginx/error.logLook for errors related to:
- DNS resolution failures
- Connection refused
- Upstream timeout
# 5. Check what's the proxy_target in nginx config
cat /tmp/nginx.conf | grep -A2 "set \$proxy_target"Expected output: set $proxy_target "http://localhost:8081";
# 6. Check DNS resolver in nginx config
cat /tmp/nginx.conf | grep resolverExpected output: resolver <IP> valid=10s ipv6=off;
# 7. Test if nginx can resolve localhost via DNS
nslookup localhostImportant: This will likely fail! Nginx resolver only queries DNS, not /etc/hosts
# 8. Check if backend is accessible on localhost
curl -v http://localhost:8081/healthExpected output: OK
# 9. Check environment variables
env | grep -E '(BACKEND_PORT|PROXY_TARGET|DNS_RESOLVER)'Expected output:
BACKEND_PORT=8081
PROXY_TARGET=http://localhost:8081
DNS_RESOLVER=<IP>
# 10. Check recent nginx access logs for API requests
tail -100 /var/log/nginx/access.log | grep "api/v1/settings"Look for 502 errors
# Try accessing backend API endpoint directly
curl http://127.0.0.1:8081/api/v1/settings/auditIf this works but nginx proxy doesn't, it's definitely a proxy configuration issue.
- Check pod logs:
kubectl logs <pod-name> -n argocd - Look for backend startup errors
- Check if backend binary exists:
ls -la /app/cased-backend
- Check if listening on correct interface (should be
0.0.0.0:8081) - Check firewall rules (unlikely in container)
- Check nginx error logs for "upstream" errors
- Check if
localhostresolves (it probably won't via DNS) - Try using
127.0.0.1instead in nginx config
Based on the symptoms, the most likely issue is:
Nginx resolver can't find localhost because:
- Nginx's
resolverdirective only queries DNS servers - DNS servers don't have a record for "localhost"
- Even though
/etc/hostshas127.0.0.1 localhost, nginx's resolver ignores it
Solution: Use 127.0.0.1 directly instead of localhost in the nginx proxy configuration.