<p>I am having issues with request to my NodeJS app running in my kubernetes cluster in digital ocean. Every request returns a <code>502 Bad Gateway Error</code>. I am not sure what I am missing.</p>
<p>This is what the service config looks like</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name:  service-api
  namespace: default
  labels:
    app:  service-api
spec:
  type: ClusterIP
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 3000
  selector:
    app:  service-api

</code></pre>
<p>The Ingress.yml looks like this</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: service-api-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/limit-connections: '2'
    nginx.ingress.kubernetes.io/limit-rpm: '60'
    service.beta.kubernetes.io/do-loadbalancer-protocol: &quot;http&quot;
    service.beta.kubernetes.io/do-loadbalancer-algorithm: &quot;round_robin&quot;
    service.beta.kubernetes.io/do-loadbalancer-http2-ports: &quot;443,80&quot;
    service.beta.kubernetes.io/do-loadbalancer-tls-ports: &quot;443&quot;
    service.beta.kubernetes.io/do-loadbalancer-tls-passthrough: &quot;true&quot;
spec:
  tls:
  - hosts:
    - dev-api.service.com
    secretName: service-api-tls
  rules:
  - host: &quot;dev-api.service.com&quot;
    http:
      paths:
      - pathType: Prefix
        path: &quot;/&quot;
        backend:
          service:
            name: service-api
            port:
              number: 80
</code></pre>
<p>Whenever I visit the host url I get a 502 error.</p>
<p>This is what appears in the nginx ingress log</p>
<pre><code>2021/01/13 08:41:34 [error] 319#319: *31338 connect() failed (111: Connection refused) while connecting to upstream, client: IP, server: dev-api.service.com, request: &quot;GET /favicon.ico HTTP/2.0&quot;, upstream: &quot;http://10.244.0.112:3000/favicon.ico&quot;, host: &quot;dev-api.service.com&quot;, referrer: &quot;https://dev-api.service.com/status&quot;
</code></pre>

<p>As we ( with @Emmanuel Amodu ) have discussed in comment:</p>
<p>mistake was to connect to app using wrong port, port <code>4000</code> instead of <code>3000</code> as defined in <code>service-api</code>.</p>
<p>For community which will have similar problem please - most important steps for debugging:</p>
<ol>
<li>Checking netstat -plant output table</li>
<li>Checking your Nginx Configuration: <code>$ kubectl exec -it -n &lt;namespace-of-ingress-controller&gt; &lt;nginx-ingress-controller-pod&gt; -- cat /etc/nginx/nginx.conf</code></li>
<li>Checking service: <code>$ kubectl describe svc service-api</code></li>
</ol>
