<p>I have a k8s deployment that contains a docker image that's running a jar that is supposed to have one HTTP 3000 port and a WebSocket 8982 port exposed.</p>
<p>When I run the standalone jar locally, I can communicate with those ports using curl and a WebSocket client.
I create a proxy using <code>kubectl proxy</code>, and go to this address:</p>
<pre><code>http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/
</code></pre>
<p>However, this request returns:</p>
<pre><code>{
  &quot;kind&quot;: &quot;Status&quot;,
  &quot;apiVersion&quot;: &quot;v1&quot;,
  &quot;metadata&quot;: {
    
  },
  &quot;status&quot;: &quot;Failure&quot;,
  &quot;message&quot;: &quot;error trying to reach service: dial tcp 10.244.0.5:80: connect: connection refused&quot;,
  &quot;code&quot;: 500
}
</code></pre>
<p>How do I access those two ports in my pod that's running the deployment?</p>

zendevil.eth
<p>you can use the command <code>kubectl port-forward</code></p>
<p>it will work like same way and create a proxy tunnel between local and cluster</p>
<p>for example, if you service name is <strong>test-service</strong></p>
<pre><code>kubectl port-forward svc/test-service 8080:3000
</code></pre>
<p>this will create the tunnel local to cluster where the local port will be <strong>8080</strong> and service port will be <strong>3000</strong> and service will route traffic to container or pod.</p>
<p>Read more at : <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/</a></p>
<p><code>kubectl proxy</code> for managing or connecting with the Kubernetes API server and use the admin APIs.</p>
<p>if you don't have the service you can directly proxy the traffic to POD from local</p>
<p>Listen on port 8888 locally, forwarding to 3000 in the pod</p>
<pre><code>kubectl port-forward pod/&lt;POD NAME&gt; 8888:3000
</code></pre>
