-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.sh
executable file
·249 lines (193 loc) · 6.81 KB
/
setup.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
INGRESS_NGINX_VERSION=3.25.0
METRICS_SERVER_VERSION=5.8.0
KUBE_PROMETHEUS_STACK_VERSION=14.3.0
MINIO_VERSION=8.0.10
LOKI_VERSION=0.28.0
PROMTAIL_VERSION=3.5.0
CANARY_VERSION=0.3.0
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd -P)
main() {
pushd "$SCRIPT_DIR" > /dev/null
if [[ -n "${1:-}" ]]; then
echo '🚀 Updating Loki demo setup...'
echo
"setup_${1}"
else
echo '🚀 Launching Loki demo setup...'
echo '⏳ This will roughly take up to 10 minutes...'
echo
setup_chart_repos
setup_cluster
setup_registry
setup_ingress_nginx
setup_metrics_server
setup_monitoring
setup_minio
setup_loki
setup_eventrouter
setup_promtail
setup_canary
setup_test_loggers
fi
echo
echo '🎉 Done.'
popd > /dev/null
}
setup_chart_repos() {
echo
echo '🟡 Adding chart repositories...'
echo
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx --force-update
helm repo add bitnami https://charts.bitnami.com/bitnami --force-update
helm repo add grafana https://grafana.github.io/helm-charts --force-update
helm repo add minio https://helm.min.io --force-update
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts --force-update
echo
echo '✅ Finished adding chart repositories.'
echo
}
setup_cluster() {
if ! (kind get clusters | grep --silent loki-minio-demo) &> /dev/null; then
echo
echo '🟡 Creating kind cluster...'
echo
kind create cluster --name=loki-minio-demo --config=config/kind/config.yaml
echo
echo '✅ Finished creating kind cluster.'
echo
else
echo
echo '📣️️ kind cluster already exists. Re-using it!'
echo
fi
}
setup_registry() {
if ! docker container inspect loki-registry-proxy &> /dev/null; then
echo
echo '🟡 Creating pull-through Docker registry...'
echo
docker container run --name loki-registry-proxy --net kind --detach \
--env REGISTRY_PROXY_REMOTEURL=https://registry-1.docker.io \
--volume "$(pwd)/.registry:/var/lib/registry" \
registry:2
echo
echo '✅ Finished creating pull-through Docker registry.'
echo
else
echo
echo '📣️️ Pull-through Docker registry already exists. Re-using it!'
echo
fi
}
setup_ingress_nginx() {
log_start ingress-nginx
helm upgrade ingress-nginx ingress-nginx/ingress-nginx --install --wait \
--version="$INGRESS_NGINX_VERSION" \
--namespace=ingress --create-namespace \
--values=config/ingress-nginx/values.yaml
log_finished ingress-nginx
}
setup_metrics_server() {
log_start metrics-server
helm upgrade metrics-server bitnami/metrics-server --install --wait \
--version="$METRICS_SERVER_VERSION" \
--namespace=kube-system \
--values=config/metrics-server/values.yaml
log_finished metrics-server
}
setup_monitoring() {
log_start monitoring
helm upgrade monitoring prometheus-community/kube-prometheus-stack --install --wait \
--version="$KUBE_PROMETHEUS_STACK_VERSION" \
--namespace=monitoring --create-namespace \
--values=config/monitoring/values.yaml
local dashboard_path
for dashboard_path in config/monitoring/dashboards/*.json; do
local name
name=$(basename "$dashboard_path")
name="dashboard-${name%.*}"
kubectl create configmap "$name" --namespace monitoring --from-file="$dashboard_path" \
--dry-run=client --output=yaml --save-config | kubectl apply --filename=-
kubectl label configmap "$name" --namespace=monitoring grafana_dashboard=1 --overwrite
done
log_finished monitoring
}
setup_minio() {
log_start MinIO
kubectl create namespace minio --dry-run=client --output=yaml --save-config | kubectl apply --filename=-
if ! kubectl get secret --namespace=minio minio-credentials > /dev/null; then
kubectl create secret generic --namespace=minio minio-credentials \
--from-literal=accesskey="$(openssl rand -hex 20)" \
--from-literal=secretkey="$(openssl rand -hex 40)"
fi
helm upgrade minio minio/minio --install --wait \
--version="$MINIO_VERSION" \
--namespace=minio \
--values=config/minio/values.yaml
log_finished MinIO
}
setup_loki() {
log_start Loki
kubectl create namespace logging --dry-run=client --output=yaml --save-config | kubectl apply --filename=-
local access_key
access_key=$(kubectl get secret --namespace=minio minio-credentials --output jsonpath="{.data.accesskey}" | base64 --decode)
local secret_key
secret_key=$(kubectl get secret --namespace=minio minio-credentials --output=jsonpath="{.data.secretkey}" | base64 --decode)
kubectl create secret generic minio-credentials --namespace=logging \
--from-literal=AWS_ACCESS_KEY="$access_key" \
--from-literal=AWS_SECRET_KEY="$secret_key" \
--dry-run=client --output=yaml --save-config | kubectl apply --filename=-
helm upgrade loki grafana/loki-distributed --install --wait --timeout=10m \
--version="$LOKI_VERSION" \
--namespace=logging \
--values=config/loki/values.yaml \
--set-file=loki.config=config/loki/config.yaml
log_finished Loki
}
setup_eventrouter() {
log_start Eventrouter
helm upgrade eventrouter charts/eventrouter --install --wait \
--namespace=logging --create-namespace
log_finished Eventrouter
}
setup_promtail() {
log_start Promtail
helm upgrade promtail grafana/promtail --install --wait \
--version="$PROMTAIL_VERSION" \
--namespace=logging --create-namespace \
--values=config/promtail/values.yaml
log_finished Promtail
}
setup_canary() {
log_start 'Loki Canary'
helm upgrade loki-canary grafana/loki-canary --install --wait \
--version="$CANARY_VERSION" \
--namespace=logging --create-namespace \
--values=config/canary/values.yaml
log_finished 'Loki Canary'
}
setup_test_loggers() {
log_start 'Test loggers'
helm upgrade test-logger-json charts/test-logger --install --wait \
--namespace=apps --create-namespace \
--values=config/test-logger/values-json.yaml
helm upgrade test-logger-logfmt charts/test-logger --install --wait \
--namespace=apps --create-namespace \
--values=config/test-logger/values-logfmt.yaml
log_finished 'Test loggers'
}
log_start() {
echo
echo "🟡 Installing $1..."
echo
}
log_finished() {
echo
echo "✅ Finished installing $1."
echo
}
main "$@"