-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_hapi_k8s.sh
More file actions
executable file
·46 lines (36 loc) · 1.49 KB
/
deploy_hapi_k8s.sh
File metadata and controls
executable file
·46 lines (36 loc) · 1.49 KB
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
#!/bin/bash
# https://bertvv.github.io/cheat-sheets/Bash.html#writing-robust-scripts-and-debugging
set -euo pipefail
# Check if required environment variables are set
# See .env-k8s-sample
: "${PROJECT_ID:?Need to set PROJECT_ID}"
: "${CLUSTER_NAME:?Need to set CLUSTER_NAME}"
: "${ZONE:?Need to set ZONE}"
: "${NAMESPACE:?Need to set NAMESPACE}"
: "${CLOUD_SQL_INSTANCE:?Need to set CLOUD_SQL_INSTANCE}"
: "${DATABASE_NAME:?Need to set DATABASE_NAME}"
: "${DATABASE_USER:?Need to set DATABASE_USER}"
: "${DATABASE_PASSWORD:?Need to set DATABASE_PASSWORD}"
: "${CHART_REPO:?Need to set CHART_REPO}"
: "${CHART_NAME:?Need to set CHART_NAME}"
# --- Functions ---
create_secret() {
local secret_name="$1"
local key="$2"
local value="$3"
kubectl create secret generic "$secret_name" --from-literal="$key=$value" -n "$NAMESPACE" || true
}
deploy_chart() {
helm install "$CHART_NAME" "$CHART_REPO/$CHART_NAME" \
-n "$NAMESPACE" \
--set spring.datasource.url="jdbc:postgresql://${CLOUD_SQL_INSTANCE}:5432/${DATABASE_NAME}" \
--set spring.datasource.username="${DATABASE_USER}" \
--set spring.datasource.password=$(kubectl get secret cloud-sql-credentials -o jsonpath="{.data.password}" -n "$NAMESPACE" | base64 --decode)
}
# --- Main Script ---
# Create Kubernetes secrets for Cloud SQL credentials
create_secret cloud-sql-credentials password "${DATABASE_PASSWORD}"
# Deploy the Helm chart
deploy_chart
echo "Deployment complete. Check the pods' status using:"
echo "kubectl get pods -n $NAMESPACE"