Skip to content

Instantly share code, notes, and snippets.

@reegnz
Created February 26, 2020 22:42
Show Gist options
  • Save reegnz/10d0fb5f92b39d35b0cf79a5d1c50744 to your computer and use it in GitHub Desktop.
Save reegnz/10d0fb5f92b39d35b0cf79a5d1c50744 to your computer and use it in GitHub Desktop.
Using sshuttle to tunnel into kubernetes

Download kuttle:

wget https://raw.githubusercontent.com/kayrus/kuttle/master/kuttle
chmod +x kuttle
mv kuttle ~/bin

create tunnel:

./tunnel.sh
!#/usr/local/bin bash
kubectl run kuttle \
--image=python:alpine \
--restart=Never \
-- sh -c 'exec tail -f /dev/null'
kube_services="$(
kubectl get svc -A -o json \
| jq -r '.items[].metadata|"\(.name).\(.namespace)"' \
| paste -d ',' -s \
)"
cluster_cidrs="$(
kubectl cluster-info dump \
| awk '
BEGIN {FS="[\"=]"}
/cluster-cidr/{print $3}
/service-cluster-ip-range/{print $3}' \
| sort | uniq | paste -s -d' '\
)"
sshuttle -r kuttle -e kuttle -v --seed-hosts "${kube_services}" ${cluster_cidrs}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment