Skip to content

Instantly share code, notes, and snippets.

Last active January 14, 2022 18:51
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
How to forward a kubectl port-forward with socat

Yo dawg, I heard you like port-fowards so I'm going to port-forward your port-forward.

Say you want to test something like maybe run something in minikube locally but connect to something running in the kube cluster.

Do your kube port foward

kubectl --context k8s-uw1-gcp port-forward prometheus-prometheus-server-7b6f9d99f8-m4vt6 9090

On your host system

socat -v TCP-LISTEN:9091,fork TCP:

Get your ip address on your host system

ip addr
# Find the correct one

Then in minikube you can now reach the kube server:

~ # printf "GET / HTTP/1.0\r\n\r\n" | nc -vvvv 9091 ( open
HTTP/1.0 302 Found
Content-Type: text/html; charset=utf-8
Location: /graph
Date: Wed, 23 May 2018 16:34:34 GMT
Content-Length: 29

<a href="/graph">Found</a>.

sent 18, rcvd 166
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment