Skip to content

Instantly share code, notes, and snippets.

@kouk
Created August 20, 2020 10:30
Show Gist options
  • Save kouk/5ee3c5892177b5db2fa22f2f0478646f to your computer and use it in GitHub Desktop.
Save kouk/5ee3c5892177b5db2fa22f2f0478646f to your computer and use it in GitHub Desktop.
#!/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 -- "$@"
@kouk
Copy link
Author

kouk commented Aug 20, 2020

Make sure it's executable and then run:

sshuttle -v -r 'none' -e /path/to/autokuttle 192.168.0.0/16

Where 192.168.0.0/16 is the network you want to tunnel through sshuttle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment