Nginx returns Bad Gateway 502 in Kubernetes Nginx returns Bad Gateway 502 in Kubernetes kubernetes kubernetes

Nginx returns Bad Gateway 502 in Kubernetes


I ran a pod using your nginx image, and this is what I get:

~# kubectl run demo --image khjoo19/nginx:v2 -- sh -c "/usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf"deployment.apps/demo createdroot@v1-16-master:~# kubectl get po -owideNAME                      READY   STATUS    RESTARTS   AGE     IP                NODE             NOMINATED NODE   READINESS GATEScurler-755cc7cfff-qjl2n   1/1     Running   5          6d1h    192.168.113.161   v1-16-worker-1   <none>           <none>debian-68649788ff-v6lrc   1/1     Running   5          5d21h   192.168.49.31     v1-16-worker-2   <none>           <none>demo-86f65d889-rfbzx      1/1     Running   0          21s     192.168.49.62     v1-16-worker-2   <none>           <none>root@v1-16-master:~# kubectl exec curler-755cc7cfff-qjl2n -- curl 192.168.49.62 2>/dev/null<html><head><title>502 Bad Gateway</title></head><body><center><h1>502 Bad Gateway</h1></center><hr><center>nginx/1.16.1</center></body></html>root@v1-16-master:~# kubectl logs demo-86f65d889-rfbzx2020/01/23 10:27:30 [crit] 9#9: *1 connect() to unix:///line_manager/tmp/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.113.161, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:///line_manager/tmp/sockets/puma.sock:/", host: "192.168.49.62"2020/01/23 10:27:30 [crit] 9#9: *1 connect() to unix:///line_manager/tmp/sockets/puma.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.113.161, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:///line_manager/tmp/sockets/puma.sock:/500.html", host: "192.168.49.62"192.168.113.161 - - [23/Jan/2020:10:27:30 +0000] "GET / HTTP/1.1" 502 157 "-" "curl/7.59.0"

Your nginx image is missing the file descriptor. And I don't see anywhere in your Deployment you are covering this.

You would need to create an emptyDir volume and map /line_manager/tmp/sockets/ directory with the directory where is you puma.sock socket descriptor; on the other container. Should work.