2026-09-28

TIL about socat, a Unix command that can be used to create bi-directional TCP proxies, much like ssh -L. Example (via), forward traffic from local port 8080 to example.com port 5545:

socat tcp-l:8080,fork,reuseaddr tcp:example.com:5545

Useful for setting up ad-hoc proxies to a Kubernetes cluster to access resources only available to the cluster itself. Launch socat using kubectx run with a port set in the cluster:

kubectl run --rm -it --port 8080 --image alpine \
   --overrides='{"metadata":{"name":"my-proxy"}}' \
   sh -- sh -c 'apk add socat && socat tcp-l:8080,fork,reuseaddr tcp:backend.example.com:5545'

Then, setup a port forward to your pod to access the port locally:

kubectl port-forward pod/my-proxy 8080:8080

With this, you can now access backend.example.com:5545 on localhost port 8080.