<p>I am trying to deploy a node js app inside a Kubernetes cluster. I have created deplyment and service(clusterIp) for that and added a role inside nginx ingress config file but seems nginx is failing to reach that service.</p>
<p>NodeJs app:</p>
<pre><code>'use strict';

const express = require('express');

// Constants
const PORT = 5678;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) =&gt; {
  console.log(&quot;request received&quot;);
  res.send('Hello World');
});

app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);
</code></pre>
<p>Dockerfile:</p>
<pre><code>FROM node:14

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

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

# Bundle app source
COPY . .

EXPOSE 5678
CMD [ &quot;node&quot;, &quot;server.js&quot; ]
</code></pre>
<p>Deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: apple-app-deployment
  labels:
    app: apple
spec:
  replicas: 2
  selector:
    matchLabels:
      app: apple
  template:
    metadata:
      labels:
        app: apple
    spec:
      containers:
      - name: apple-app
        image: anudcker/node-web-appp:1
        ports:
        - containerPort: 5678
</code></pre>
<p>Service:</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: apple-service
spec:
  selector:
    app: apple
  ports:
    - port: 5678 # Default port for image
      targetPort: 5678
</code></pre>
<p>Ingress:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    # kubernetes.io/ingress.class: azure/application-gateway
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
        - path: /apple
          pathType: Prefix
          backend:
            service:
                name: apple-service
                port:
                    number: 5678
</code></pre>
<p>Now whenever I am trying to reach the service by hitting /apple I am getting a response
<code>Cannot GET /apple</code> from Nginx ingress. I found bellow log inside nginx ingress controller pod.</p>
<pre><code>10.244.1.1 - - [07/May/2021:06:22:29 +0000] &quot;GET /apple HTTP/1.1&quot; 404 144 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36&quot; 465 0.004 [demo-apple-service-5678] [] 10.244.0.24:5678 144 0.004 404 5a5bdf8f61d59b665218be0a18a6ab4c
</code></pre>
<p>Any Idea?</p>

Anup
<p>The issue is that you are using <code>rewrite-target</code> of <code>networking.k8s.io/v1beta1</code>, with the <code>apiVersion: networking.k8s.io/v1</code>.</p>
<p>You need to update your annotation to the new one:</p>
<p><code>nginx.ingress.kubernetes.io/rewrite-target: /</code></p>
