forked from masezou/k8s-study-vanilla
-
Notifications
You must be signed in to change notification settings - Fork 1
/
P-postgresql-app.sh
executable file
·53 lines (46 loc) · 1.88 KB
/
P-postgresql-app.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
#########################################################
PGNAMESPACE=postgresql-app
# SC = csi-hostpath-sc / local-path / nfs-csi / vsphere-sc / cstor-csi-disk
SC=vsphere-sc
SAMPLEDATA=1
#########################################################
### Install command check ####
if type "kubectl" > /dev/null 2>&1
then
echo "kubectl was already installed"
else
echo "kubectl was not found. Please install kubectl and re-run"
exit 255
fi
if type "helm" > /dev/null 2>&1
then
echo "helm was already installed"
else
if [ ! -f /usr/local/bin/helm ]; then
curl -s -O https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
bash ./get-helm-3
helm version
rm get-helm-3
helm completion bash > /etc/bash_completion.d/helm
source /etc/bash_completion.d/helm
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
fi
fi
helm repo add bitnami https://charts.bitnami.com/bitnami
kubectl create namespace ${PGNAMESPACE}
if [ ${SC} = csi-hostpath-sc ]; then
helm install --namespace ${PGNAMESPACE} postgres bitnami/postgresql --set volumePermissions.enabled=true --set global.storageClass=${SC}
else
helm install --namespace ${PGNAMESPACE} postgres bitnami/postgresql --set global.storageClass=${SC}
fi
if [ ${SAMPLEDATA} -eq 1 ]; then
export POSTGRES_PASSWORD=$(kubectl get secret --namespace ${PGNAMESPACE} postgres-postgresql -o jsonpath="{.data.postgresql-password}" | base64 --decode)
kubectl port-forward --namespace ${PGNAMESPACE} svc/postgres-postgresql 5432:5432 &
PGPASSWORD="$POSTGRES_PASSWORD" createdb --host 127.0.0.1 -U postgres pgbenchdb
PGPASSWORD="$POSTGRES_PASSWORD" pgbench --host 127.0.0.1 -U postgres -i pgbenchdb
PGPASSWORD="$POSTGRES_PASSWORD" pgbench --host 127.0.0.1 -U postgres -c 10 -t 1000 pgbenchdb
fi
kubectl annotate statefulset postgres-postgresql kanister.kasten.io/blueprint='postgresql-hooks' \
--namespace=${PGNAMESPACE}