<p>If you have access to <code>kubectl</code>, try</p>
<p><code>kubectl port-forward service/&lt;servicename&gt; 8000:30085</code>.</p>

CC BY-SA 4.0
2023-01-02T02:24:01.470Z
2023-01-02T02:24:01.470Z
benjimin
<p>Expose SSH on the pod and use SSH to do the reverse port forward</p>
<p>or</p>
<p>Use a service on the cluster pointing at your machine but that assumes the networking is connected some how</p>
<p>Those 2 anwsers were taken from this duplicate question. <a href="https://stackoverflow.com/questions/66666273/forward-traffic-from-kubernetes-pod-to-local-server">https://stackoverflow.com/questions/66666273/forward-traffic-from-kubernetes-pod-to-local-server</a></p>
<p>I think a third better approach might be to use somekinda mesh VPN like <a href="https://tailscale.com/" rel="nofollow noreferrer">https://tailscale.com/</a></p>

CC BY-SA 4.0
2022-08-04T18:21:06.057Z
2022-08-04T18:21:06.057Z
Levi
<p>I am attempting to reverse port forward information from a Kubernetes pod <strong>192.168.49.2:30085</strong> to my <strong>locoalhost:8000</strong> but I am having issues.</p>
<p>The goal is to get the same response as <code>curl 192.168.49.2:30085</code>  on localhost:8000</p>
<p>One thing I have tried has been using <a href="https://github.com/omrikiei/ktunnel" rel="nofollow noreferrer">ktunnel</a> with the command <code>ktunnel expose &lt;service_name&gt; 30085:8000</code> to try to forward this info. Doing this I get the output</p>
<pre><code>INFO[0000] Exposed service's cluster ip is: 10.101.77.99
.INFO[0000] waiting for deployment to be ready
.....
INFO[0001] port forwarding to https://192.168.49.2:8443/api/v1/namespaces/default/pods/thisisatest-59d5584c84-b5qrc/portforward
INFO[0001] Waiting for port forward to finish
INFO[0001] Forwarding from 127.0.0.1:28688 -&gt; 28688
INFO[2022-08-03 20:23:48.605] starting tcp tunnel from source 30085 to target 8000
</code></pre>
<p>Which seems normal and I am able to get a response when using <code>curl http://10.101.77.99:30085</code>  on local host 8000 but not the correct response.</p>
<p>I have also attempted to run a tcp server with the <a href="https://webapp.io/blog/container-tcp-tunnel/" rel="nofollow noreferrer">command</a> <code>nc 127.0.0.1 8000 | kubectl exec -i &lt;pod_name&gt; tcpserver 127.0.0.1 30085 cat</code> But am having poor results as well. Am I using these services incorrectly? Or is there a better way to do this all together?</p>

<docker><kubernetes><ports>
What is the best way to reverse port forward information from a Kubernetes cluster to localhost?
garrett_17
# What is the best way to reverse port forward information from a Kubernetes cluster to localhost?

(Asked by: username_0 on 2022-08-03)

I am attempting to reverse port forward information from a Kubernetes pod 192.168.49.2:30085 to my locoalhost:8000 but I am having issues.
The goal is to get the same response as curl 192.168.49.2:30085  on localhost:8000
One thing I have tried has been using ktunnel with the command ktunnel expose  30085:8000 to try to forward this info. Doing this I get the output
INFO[0000] Exposed service's cluster ip is: 10.101.77.99
.INFO[0000] waiting for deployment to be ready
.....
INFO[0001] port forwarding to https://192.168.49.2:8443/api/v1/namespaces/default/pods/thisisatest-59d5584c84-b5qrc/portforward
INFO[0001] Waiting for port forward to finish
INFO[0001] Forwarding from 127.0.0.1:28688 -> 28688
INFO[2022-08-03 20:23:48.605] starting tcp tunnel from source 30085 to target 8000

Which seems normal and I am able to get a response when using curl http://10.101.77.99:30085  on local host 8000 but not the correct response.
I have also attempted to run a tcp server with the command nc 127.0.0.1 8000 | kubectl exec -i  tcpserver 127.0.0.1 30085 cat But am having poor results as well. Am I using these services incorrectly? Or is there a better way to do this all together?

**Tags:** docker, kubernetes, ports


---

## 2 answers

### Answer by username_1 on 2023-01-02. Score: 1

If you have access to `kubectl`, try

`kubectl port-forward service/ 8000:30085`.


---

### Answer by username_2 on 2022-08-04. Score: 0

Expose SSH on the pod and use SSH to do the reverse port forward

or

Use a service on the cluster pointing at your machine but that assumes the networking is connected some how

Those 2 anwsers were taken from this duplicate question. <https://stackoverflow.com/questions/66666273/forward-traffic-from-kubernetes-pod-to-local-server>

I think a third better approach might be to use somekinda mesh VPN like <https://tailscale.com/>


---

