Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save marcelaraujo/9dcc43dd8a53a44303fb382dd2d4d40b to your computer and use it in GitHub Desktop.

Select an option

Save marcelaraujo/9dcc43dd8a53a44303fb382dd2d4d40b to your computer and use it in GitHub Desktop.
K8S Port Forward
If you want to forward a non-k8s-managed port and have permission to stand up a new pod, you can run the alpine/socat image and port-forward to that:
kubectl run --restart=Never --image=alpine/socat TEMP_POD_NAME -- -d -d tcp-listen:PORT,fork,reuseaddr tcp-connect:HOSTNAME:PORT
kubectl wait --for=condition=Ready pod/TEMP_POD_NAME
kubectl port-forward pod/TEMP_POD_NAME LOCAL_PORT:PORT
Don't forget to bring the pod down once you're done.
kubectl delete pod/TEMP_POD_NAME --grace-period 1 --wait=false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment