The pod sat running, but you couldn’t reach it. The logs were clean. The service was fine. The firewall was open. And still—no connection.
This is where kubectl and socat work together like a scalpel. With kubectl exec and socat, you can bridge a port from inside a pod to your local system without exposing it cluster-wide. It’s precise, private, and fast.
Why kubectl socat matters
Sometimes you need to debug a service that isn’t exposed externally. Port-forwarding is common, but kubectl port-forward relies on Kubernetes API tunnels and has quirks with certain protocols. socat can proxy raw TCP, UDP, and UNIX sockets directly. Pairing it with kubectl exec lets you create bidirectional pipes on demand, hitting targets inside the cluster with zero YAML changes.
Basic example
First, run socat inside the pod:
kubectl exec -it my-pod -- socat TCP-LISTEN:9000,fork TCP:internal-service:80
This listens on port 9000 in the pod and forwards to an internal service on port 80.
Then, from your local machine, set up port forwarding with kubectl port-forward: