# This is only required on WINDOWS Powershell: make sure $USER contains your username
# $USER = $env:UserName
# Create a socat container to tunnel to the postgres service
# This will run in foreground so you'll need a separate terminal to open the port-forward
kubectl -n __KUBERNETES_NAMESPACE__ run postgres-tunnel-$USER -it --image=alpine/socat --tty --rm --expose=true --port=5432 tcp-listen:5432,fork,reuseaddr tcp-connect:__POSTGRES_SERVICE_NAME__:5432
######
# IN ANOTHER TERMINAL
######
# Open a port-forward to the socat container
kubectl -n __KUBERNETES_NAMESPACE__ port-forward svc/postgres-tunnel-$USER 54320:5432
# Now you can connect using your favorite postgres client using
host: localhost
port: 54320
Creating a Postgres tunnel in Kubernetes
2024-06-12
See Also
Fixing Sentry Snuba migrations
Tutorial - Kubernetes Operator with Kubebuilder part 3
Tutorial - Kubernetes Operator with Kubebuilder part 2
Tutorial - Kubernetes Operator with Kubebuilder part 1
Tutorial - Terraform: Create a GKE cluster with access to Cloud SQL
How to debug Varnish? - A detailed guide with some practical examples
Tutorial - Kubernetes Operator with Kubebuilder part 3
Tutorial - Kubernetes Operator with Kubebuilder part 2
Tutorial - Kubernetes Operator with Kubebuilder part 1
Tutorial - Terraform: Create a GKE cluster with access to Cloud SQL
How to debug Varnish? - A detailed guide with some practical examples