Created
February 22, 2021 15:06
-
-
Save maxisme/02b18b77f9919955eafa8c5792273279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
POSTGRES_PASSWORD=$(kubectl get secret --namespace default pg-postgresql-ha-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode) | |
db_cmd="kubectl run pg-postgresql-ha-client --rm --tty -i --restart='Never' --overrides='{\"spec\": {\"nodeSelector\": {\"kubernetes.io/arch\": \"amd64\"}}}' --image docker.io/bitnami/postgresql-repmgr:11.10.0-debian-10-r55 --env='PGPASSWORD=$POSTGRES_PASSWORD' --command -- psql -h pg-postgresql-ha-pgpool -p 5432 -U postgres -d postgres" | |
read -p "Database name: " DB_NAME | |
read -p "Username for $DB_NAME: " USERNAME | |
read -p "Password for $USERNAME: " PASSWORD | |
eval "$db_cmd -c 'CREATE DATABASE $DB_NAME;'" | |
eval "$db_cmd -c \"CREATE USER $USERNAME WITH ENCRYPTED PASSWORD '$PASSWORD';\"" | |
eval "$db_cmd -c \"GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $USERNAME;\"" | |
eval "$db_cmd -c \"REVOKE connect ON DATABASE $DB_NAME FROM PUBLIC;\"" | |
eval "$db_cmd -c \"GRANT connect ON DATABASE $DB_NAME TO $USERNAME;\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment