-
Notifications
You must be signed in to change notification settings - Fork 0
/
createSecret.sh
30 lines (22 loc) · 900 Bytes
/
createSecret.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# First, install the PostgreSQL chart
# helm install my-postgresql bitnami/postgresql
# Allow the PostgreSQL pod to start up
# sleep 30
# Fetch the generated password
DB_PASSWORD=$(kubectl get secret --namespace default my-postgresql -o jsonpath="{.data.postgres-password}" | openssl base64 -d -A)
# Try to fetch the username. If it doesn't exist, default to "postgres".
DB_USERNAME=$(kubectl get secret --namespace default my-postgresql -o jsonpath="{.data.postgres-username}" | openssl base64 -d -A)
if [ -z "$DB_USERNAME" ]
then
DB_USERNAME="postgres"
fi
if [[ -z "${DB_PASSWORD}" ]]; then
echo "DB_PASSWORD environment variable is not set"
sleep 5
exit 1
fi
# Now we create the Kubernetes secret with the username and password
kubectl create secret generic db-credentials --from-literal=username=$DB_USERNAME --from-literal=password=$DB_PASSWORD
echo "Done"
sleep 5