Skip to content

Instantly share code, notes, and snippets.

Last active January 6, 2023 10:14
  • Star 0 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?
kubectl jump server via kubectl port-forward
#!/usr/bin/env bash
# Allows you to connect to remote endpoints via port forward
set -e
function cleanup {
echo ""
kubectl delete pod/$TEMP_POD_NAME --grace-period 1 --wait=false
trap cleanup EXIT
kubectl run --restart=Never --image=alpine/socat $TEMP_POD_NAME -- -d -d tcp-listen:$REMOTE_PORT,fork,reuseaddr tcp-connect:$REMOTE_HOST:$REMOTE_PORT
kubectl wait --for=condition=Ready pod/$TEMP_POD_NAME
kubectl port-forward pod/$TEMP_POD_NAME $LOCAL_PORT:$REMOTE_PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment