<p>I am deploying nodejs application on kubernetes, After deployment pod is up and running, but when I am trying to access the application through ingress it is giving 502 bad gateway error.</p>
<p>Dockerfile</p>
<pre><code>FROM node:14

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 3123
CMD [ &quot;node&quot;, &quot;index.js&quot; ]

</code></pre>
<p>Deployment.yaml</p>
<pre><code>---
  apiVersion: &quot;apps/v1&quot;
  kind: &quot;Deployment&quot;
  metadata: 
    name: &quot;node-development&quot;
    namespace: &quot;development&quot;
  spec: 
    selector: 
      matchLabels: 
        app: &quot;node-development&quot;
    replicas: 1
    template: 
      metadata: 
        labels: 
          app: &quot;node-development&quot;
      spec: 
        containers: 
          - 
            name: &quot;node-development&quot;
            image: &quot;xxx&quot;
            imagePullPolicy: &quot;Always&quot;
            env: 
              - 
                name: &quot;NODE_ENV&quot;
                value: &quot;development&quot;
            ports: 
              - 
                containerPort: 47033

</code></pre>
<p>service.yaml</p>
<pre><code>---
  apiVersion: &quot;v1&quot;
  kind: &quot;Service&quot;
  metadata: 
    name: &quot;node-development-service&quot;
    namespace: &quot;development&quot;
    labels: 
      app: &quot;node-development&quot;
  spec: 
    ports: 
      - 
        port: 47033
        targetPort: 3123
    selector: 
      app: &quot;node-development&quot;

</code></pre>
<p>ingress.yaml</p>
<pre><code>---
  apiVersion: &quot;networking.k8s.io/v1&quot;
  kind: &quot;Ingress&quot;
  metadata: 
    name: &quot;node-development-ingress&quot;
    namespace: &quot;development&quot;
    annotations: 
      nginx.ingress.kubernetes.io/rewrite-target: &quot;/$1&quot;
  spec: 
    rules: 
      - 
        host: &quot;xxxx&quot;
        http: 
          paths: 
            - 
              backend: 
                service:
                  name: &quot;node-development&quot;
                  port: 
                    number: 47033
              path: &quot;/node-development/(.*)&quot;
              pathType: &quot;ImplementationSpecific&quot;

</code></pre>
<p>With ingress or even with the pod cluster ip I am not being able to access application it is throwing 502 bad gateway nginx</p>

SVD
<p>Issue got resolved, I am using SSL in my application as a result it was not re-directing with the given ingress url.</p>
<p>Need to add below annotation in ingress.yaml file.</p>
<pre><code>nginx.ingress.kubernetes.io/ssl-passthrough: &quot;true&quot;
nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTPS&quot;

</code></pre>
