Add ability to create dbs

This commit is contained in:
Kasper Juul Hermansen 2022-06-04 17:10:05 +02:00
parent 887424946f
commit 268b4693cf
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#!/bin/bash
set -e
SUBJECT=$1
PGPASSWORD=$2
PASSWORD=$(openssl rand -hex 20)
ID=$(openssl rand -hex 5)
kubectl run "postgres-client-$ID" --rm -i --image "bitnami/postgresql" -n postgres --env="PGPASSWORD=$PGPASSWORD" --command -- psql --host postgres-postgresql -U postgres <<SQL
CREATE DATABASE $SUBJECT;
CREATE USER $SUBJECT with encrypted password '$PASSWORD';
grant all privileges on database $SUBJECT to $SUBJECT;
SQL
echo "$PASSWORD"

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
PGPASSWORD=$1
kubectl run postgres-client --rm --tty -i --image "bitnami/postgresql" -n postgres --env="PGPASSWORD=$PGPASSWORD" --command -- psql --host postgres-postgresql -U postgres