Skip to content

Instantly share code, notes, and snippets.

@jirfag
Created March 29, 2020 17:00
Show Gist options
  • Save jirfag/c689fb133315c311843d716d444de8b7 to your computer and use it in GitHub Desktop.
Save jirfag/c689fb133315c311843d716d444de8b7 to your computer and use it in GitHub Desktop.
Kubernetes connect to PostgreSQL
#!/bin/bash
set -ue
PGPASSWORD=$(kubectl get secret -n postgres pg-su -o jsonpath="{.data.password}" | base64 --decode)
PGUSER=$(kubectl get secret -n postgres pg-su -o jsonpath="{.data.username}" | base64 --decode)
BASH_CMD="PGPASSWORD=${PGPASSWORD} psql -h pg-stolon-proxy.postgres -U ${PGUSER} -d api_prod"
kubectl -n postgres exec -ti pg-stolon-keeper-0 -- bash -c "${BASH_CMD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment