-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathkubermatic-deploy.sh
executable file
·164 lines (142 loc) · 5.04 KB
/
kubermatic-deploy.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
# Kubermatic Deployment script based on helm3
set -euo pipefail
BASEDIR=$(dirname "$0")
source $BASEDIR/../../hack/lib.sh
if [[ $# -lt 1 ]] || [[ "$1" == "--help" ]]; then
echo "Usage: $(basename \"$0\") (master|seed) path/to/VALUES_FILES path/to/CHART_FOLDER (monitoring|logging|backup|kubermatic|kubermatic-deployment-only)"
echo "FYI: kubermatic|kubermatic-deployment-only is deprecated due to new kubermatic-installer binary"
exit 1
fi
DEPLOY_TYPE="$1"
if [[ "$DEPLOY_TYPE" = master ]]; then
MASTER_FLAG="--set=kubermatic.isMaster=true"
elif [[ "$DEPLOY_TYPE" = seed ]]; then
MASTER_FLAG="--set=kubermatic.isMaster=false"
else
echo "invalid deploy type, expected (master|seed), got $DEPLOY_TYPE"
fi
VALUES_FILE=$(realpath "$2")
if [[ ! -f "$VALUES_FILE" ]]; then
echodate "'values.yaml' in folder not found! \nCONTENT $VALUES_FILE:\n`ls -l $VALUES_FILE/..`"
exit 1
fi
CHART_FOLDER=$(realpath "$3")
if [[ ! -d "$CHART_FOLDER" ]]; then
echodate "CHART_FOLDER not found! $CHART_FOLDER"
exit 1
fi
### verification is checked in case expresion
DEPLOY_STACK="$4"
DEPLOY_CERTMANAGER=true
DEPLOY_MINIO=true
DEPLOY_ALERTMANAGER=true
DEPLOY_LOKI=true
DEPLOY_IAP=true
#CANARY_DEPLOYMENT=true
#verify Helm3
[[ $(helm version --short) =~ ^v3.*$ ]] && echo "helm3 detected!" || (echo "This script requires helm3! Please install helm3: https://helm.sh/docs/intro/install" && exit 1)
function deploy {
local name="$1"
local namespace="$2"
local path="$CHART_FOLDER/$3"
local timeout="${4:-300s}"
if [[ ! -d "$path" ]]; then
echo "chart not found! $path"
exit 1
fi
TEST_NAME="[Helm] Deploy chart $name"
if [[ -v CANARY_DEPLOYMENT ]]; then
inital_revision="$(helm history $name --output=json | jq '.Releases[0].Revision')"
fi
echodate "Fetching dependencies for chart $name ..."
requiresUpdate=false
chartname=$(yq eval .name $path/Chart.yaml )
i=0
for url in $(yq eval '.dependencies[]|select(.repository != null)|.repository' $path/Chart.yaml); do
i=$((i + 1))
helm repo add ${chartname}-dep-${i} ${url}
requiresUpdate=true
done
if $requiresUpdate; then
helm repo update
fi
echodate "Upgrading [$namespace] $name ..."
kubectl create namespace "$namespace" || true
helm dependency build $path
helm upgrade --install --wait --timeout $timeout $MASTER_FLAG --values "$VALUES_FILE" --namespace "$namespace" "$name" "$path"
if [[ -v CANARY_DEPLOYMENT ]]; then
TEST_NAME="[Helm] Rollback chart $name"
echodate "Rolling back $name to revision $inital_revision as this was only a canary deployment"
helm rollback --wait --timeout "$timeout" "$name" "$inital_revision"
fi
unset TEST_NAME
}
function deployBackup() {
# CI has its own Minio deployment as a proxy for GCS, so we do not install the default Helm chart here.
if [[ -v DEPLOY_MINIO ]]; then
deploy minio minio minio/
deploy s3-exporter kube-system s3-exporter/
fi
if [[ -d "$CHART_FOLDER/backup/velero/crd" ]]; then
kubectl apply -f "$CHART_FOLDER/backup/velero/crd"
fi
deploy velero velero backup/velero
}
function deployCertManager() {
if [[ -v DEPLOY_CERTMANAGER ]]; then
#### CERT-MANAGER
kubectl apply -f "$CHART_FOLDER/cert-manager/crd"
deploy cert-manager cert-manager cert-manager/
fi
}
function deployIAP() {
# We might have not configured IAP which results in nothing being deployed. This triggers https://github.com/helm/helm/issues/4295 and marks this as failed
# We hack around this by grepping for a string that is mandatory in the values file of IAP
# to determine if its configured, because am empty chart leads to Helm doing weird things
if [[ -v DEPLOY_IAP ]]; then
### not used until iap ca field is not in chart
if grep -q oidc_issuer_url "$VALUES_FILE"; then
deploy iap iap iap/
else
echodate "Skipping IAP deployment because discovery_url is unset in values file"
fi
fi
}
echodate "Deploying $DEPLOY_STACK stack..."
case "$DEPLOY_STACK" in
monitoring)
deployIAP
deploy node-exporter monitoring monitoring/node-exporter/
deploy kube-state-metrics monitoring monitoring/kube-state-metrics/
deploy grafana monitoring monitoring/grafana/
deploy blackbox-exporter monitoring monitoring/blackbox-exporter/
if [[ -v DEPLOY_ALERTMANAGER ]]; then
deploy alertmanager monitoring monitoring/alertmanager/
fi
deploy prometheus monitoring monitoring/prometheus/ 900s
;;
logging)
#### elastic stack removed -> Loki
if [[ "${DEPLOY_LOKI}" = true ]]; then
deploy "loki" "logging" logging/loki/
deploy "promtail" "logging" logging/promtail/ 900s
fi
;;
kubermatic)
deploy nginx-ingress-controller nginx-ingress-controller nginx-ingress-controller/
deployCertManager
if [[ "$DEPLOY_TYPE" == master ]]; then
deploy oauth oauth oauth/
fi
deployBackup
;;
cert-manager)
deployCertManager
;;
backup)
deployBackup
;;
*)
echo "error: no DEPLOY_STACK defined"
esac