Skip to content

Instantly share code, notes, and snippets.

@jedvardsson
Last active November 29, 2022 09:40
Show Gist options
  • Save jedvardsson/27ba72a402d0bea42d78e98f95594e92 to your computer and use it in GitHub Desktop.
Save jedvardsson/27ba72a402d0bea42d78e98f95594e92 to your computer and use it in GitHub Desktop.
How to setup a port-forward to any host reachable from kubernetes
# How to set up a port-forward to any host reachable from a kubernetes namespace.
# Start a jump-off-pod with `socat` installed in a new terminal (unless there is a pod with socat installed)
kubectl run -it --rm --restart=Never jump-off-pod --image=wbitt/network-multitool:alpine-extra -- bash
# local socat that forward local port over stdio to a socat in a kubernetes pod
socat TCP-LISTEN:${LOCAL_PORT},reuseaddr,fork 'EXEC:"kubectl exec -i jump-off-pod -- socat STDIO TCP-CONNECT:${REMOTE_HOST}:${REMOTE_PORT}"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment