Last active
February 2, 2022 06:53
-
-
Save ypresto/ee4406de785325b3feaa4fc5be6f7ead to your computer and use it in GitHub Desktop.
Port forward to somewhere only accessible from Kubernetes cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -ex | |
# $1: host | |
# $2: port | |
# $3: local port (defaults to $2) | |
pod_name=bastion-$USER | |
# extend timeout for fargate env | |
( sleep 3 && kubectl wait --for=condition=ready --timeout=1m0s pod/$pod_name && echo Start port forwarding && kubectl port-forward pod/$pod_name ${3:-$2}:$2 ) & | |
kubectl run $pod_name --rm -i --tty --image alpine --pod-running-timeout=1m0s -- sh -c "apk add socat && socat tcp-listen:$2,reuseaddr,fork tcp-connect:$1:$2" | |
kill -INT $! # kill last background job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment