ProHoster > Blog > Administration > How to open tunnel to Kubernetes pod or container with tcpserver and netcat
How to open tunnel to Kubernetes pod or container with tcpserver and netcat
Note. transl.: This practical note from the creator of LayerCI is a great illustration of the so-called tips & tricks for Kubernetes (and not only). The solution proposed here is only one of the few and, perhaps, not the most obvious (for some cases, the βnativeβ for K8s already mentioned in the comments may be suitable kubectl port-forward). However, it allows you to at least look at the problem from the perspective of using classic utilities and combining them further - at the same time simple, flexible and powerful (see "other ideas" at the end for inspiration).
Imagine a typical situation: you want a port on your local machine to magically redirect traffic to a pod/container (or vice versa).
Possible use cases
Check what HTTP endpoint returns /healthz pod in the production cluster.
Connect a TCP debugger to a pod on the local machine.
Get access to the production database from local database tools without having to fiddle with authentication (localhost usually has root permissions).
Run a one-time migration script for data in a staging cluster without having to create a container for it.
Connect a VNC session to a pod running a virtual desktop (see XVFB).
A few words about the necessary tools
tcpserver - An open source utility available in most Linux package repositories. It allows you to open a local port and redirect traffic received via stdin / stdout from any specified command to it: