Skip to content

Instantly share code, notes, and snippets.

@alexrios
Created December 10, 2020 01:40
Show Gist options
  • Save alexrios/d7e5cbd299f66fab1edb54a87d219f09 to your computer and use it in GitHub Desktop.
Save alexrios/d7e5cbd299f66fab1edb54a87d219f09 to your computer and use it in GitHub Desktop.
Tuneling RDS through K8S
#!/usr/bin/env bash
set -e
TEMP_POD_NAME=postgres-jump-server
LOCAL_PORT=5433
REMOTE_HOST=<postgres-host>
REMOTE_PORT=5432
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