Created
August 20, 2020 10:30
-
-
Save kouk/5ee3c5892177b5db2fa22f2f0478646f to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Inspired by: https://github.com/kayrus/kuttle | |
# Usage: | |
# | |
# sshuttle -v -r 'none' -e /path/to/this_script 172.20.0.0/16 | |
# | |
set -e | |
VERSION=0.1 | |
if [ "$1" == "--version" ] ; then | |
echo "Version: $VERSION" | |
exit | |
fi | |
NAME=$(basename $0) | |
DEPLOYMENT="deployment/$NAME" | |
# skip until python command | |
# https://github.com/sshuttle/sshuttle/blob/45f8cce2f892749a0971f0d1e299dcdc32f88afe/sshuttle/ssh.py#L141 | |
while [ $# -gt 0 ] ; do | |
arg=$1 | |
shift | |
if [ "$arg" == "--" ] ; then | |
break | |
fi | |
done | |
if [ $# -lt 1 ] ; then | |
printf "Missing command to exec in pod!\n" | |
exit 1 | |
fi | |
if [ -z "$(kubectl get -n default $DEPLOYMENT -o name --ignore-not-found)" ] ; then | |
kubectl create -n default --save-config -f - >/dev/null <<EOF | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: $NAME | |
creator: $(whoami) | |
name: $NAME | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: $NAME | |
template: | |
metadata: | |
labels: | |
app: $NAME | |
spec: | |
containers: | |
- image: python:3-alpine | |
name: python | |
command: ["sh"] | |
args: ["-c", "exec tail -f /dev/null"] | |
EOF | |
fi | |
kubectl wait po -l app=$NAME -n default --for condition=Ready --timeout 30s >/dev/null | |
eval exec kubectl exec --namespace=default -i $DEPLOYMENT -- "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure it's executable and then run:
Where 192.168.0.0/16 is the network you want to tunnel through sshuttle.