<p>I have a very simple node.js app, server is listening on port <code>8282</code>:</p>
<pre><code>const http = require('http');
const os = require('os');
...
...
var server = http.createServer(handler);
server.listen(8282);  
</code></pre>
<p>I have a <code>Dockerfile</code> for it:</p>
<pre><code>FROM node:12
COPY app.js /app.js
ENTRYPOINT [&quot;node&quot;,&quot;app.js&quot;]
</code></pre>
<p>Then I built the image <code>myreg/my-app:1.0</code> successfully &amp; deployed to my k8s cluster (AWS EKS) with the following manifest:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: my-ns
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: myreg/my-app:1.0
        ports:
        - containerPort: 8282
      imagePullSecrets:
      - name: my-reg-cred

---
apiVersion: v1
kind: Service
metadata:
  name: my-svc
  namespace: my-ns
spec:
  ports:
    - name: http
      port: 8282
      targetPort: 8282
  selector:
    app: my-app
</code></pre>
<p>I can see pods are running:</p>
<pre><code>kubectl --namespace=my-ns get po
NAME                      READY   STATUS    RESTARTS   AGE
my-app-5477c9c798-5q4v4   1/1     Running   0          5m3s
</code></pre>
<p>Then I want to do <code>port-forwarding</code>, on my terminal:</p>
<pre><code>$kubectl --namespace=my-ns port-forward my-app-5477c9c798-5q4v4  8282
Forwarding from 127.0.0.1:8282 -&gt; 8282
Forwarding from [::1]:8282 -&gt; 8282
</code></pre>
<p>I open another terminal window, using curl to communicate with my pod:</p>
<pre><code>curl localhost:8282
curl: (52) Empty reply from server
</code></pre>
<p>On the other terminal window where port-forwarding is running:</p>
<pre><code>Handling connection for 8282
E0411 23:12:25.254291   45793 portforward.go:400] an error occurred forwarding 8282 -&gt; 8282: error forwarding port 8282 to pod ca30fad7ea7100d684d1743573dea426caa9a333163ccbca395ed57eaa363061, uid : exit status 1: 2022/04/11 20:12:25 socat[1326] E connect(5, AF=2 127.0.0.1:8282, 16): Connection refused
</code></pre>
<p>Why port forwarding is failed in my implementation? What do I miss?</p>

user842225
<p>You app is only <a href="https://nodejs.org/api/net.html#netcreateconnectionport-host-connectlistener" rel="nofollow noreferrer">listen to localhost</a>, try change <code>server.listen(8282)</code> to <code>server.listen(8282,&quot;0.0.0.0&quot;)</code>, rebuild and update your image and restart your deployment.</p>
