kubernetes-state/infrastructure/postgres/create-db.sh
2022-06-04 17:10:05 +02:00

18 lines
445 B
Bash
Executable File

#!/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"