This repository was archived by the owner on Nov 1, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy path.functions
More file actions
504 lines (434 loc) · 18.7 KB
/
Copy path.functions
File metadata and controls
504 lines (434 loc) · 18.7 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
cleanup() {
echo "Caught CTRL+C, aborting and cleaning up"
k3d delete --name dev
if [[ -d $PWD/$K3D_MOUNT_DIR ]]; then
rm -rf $PWD/$K3D_MOUNT_DIR
fi
}
choose_ci() {
CICD=`dialog --radiolist "Install CI/CD" 0 0 5 \
tekton "Kubernetes-native CI/CD" on \
argocd "Declarative GitOps CD for Kubernetes" off \
rio "Application Deployment Engine for Kubernetes" off \
drone "Self-service Continuous Delivery platform" off \
concourse "An open-source continuous thing-doer" off \
3>&1 1>&2 2>&3`
dialog --clear
}
choose_ingress() {
INGRESS=`dialog --radiolist "Install Ingress Controller" 0 0 5 \
nginx "High Performance Load Balancer" off \
traefik "Open-source Edge Router" off \
traefik2 "Traefik in even better!" on \
istio "An open platform to connect, manage, and secure microservices" off \
none "For example if you want to use ranchers rdns service, or some awesome tool that is not included yet" off \
3>&1 1>&2 2>&3`
dialog --clear
#clear
}
choose_tools() {
TOOLS=`dialog --checklist "Install Tools" 0 0 8 \
grafana "Open source analytics and monitoring solution for every database" on \
prometheus "Monitoring system & time series database" on \
jaeger "Open source, end-to-end distributed tracing" on \
registry "A private Docker Registry if you don't have one at hand for testing" on \
minio "High Performance, Kubernetes Native Object Storage" on \
k8s-dashboard "General purpose, web-based UI for Kubernetes clusters" on \
rio-dashboard "Rancher RIOs built-in dashboard" off \
istio "Connect, secure, control, and observe services with Istio Servicemesh" off \
3>&1 1>&2 2>&3`
dialog --clear
#clear
}
choose_db() {
DB=`dialog --checklist "Install DB" 0 0 2 \
cassandra "Manage massive amounts of data, fast, without losing sleep" off \
none "If you don't want any DB" off \
3>&1 1>&2 2>&3`
dialog --clear
}
prep_setup() {
echo "Preparing Setup"
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if grep -q Microsoft /proc/version; then
KUBECTL_URL="https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/windows/amd64/kubectl.exe"
K3D_URL="https://github.com/rancher/k3d/releases/download/${K3D_VERSION}/k3d-windows-amd64.exe"
TKN_URL="https://github.com/tektoncd/cli/releases/download/${TEKTON_VERSION}/tkn_${TEKTON_VERSION:1}_Windows_x86_64.zip"
RIO_URL="https://github.com/rancher/rio/releases/download/${RIO_VERSION}/rio-windows-amd64"
HELM_URL="https://get.helm.sh/helm-${HELM_VERSION}-windows-amd64.zip"
DRONE_URL=""
DISTROSHELL="WSL"
else
DISTROSHELL="BASH"
KUBECTL_URL="https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl"
K3D_URL="https://github.com/rancher/k3d/releases/download/${K3D_VERSION}/k3d-linux-amd64"
TKN_URL="https://github.com/tektoncd/cli/releases/download/${TEKTON_VERSION}/tkn_${TEKTON_VERSION:1}_Linux_x86_64.tar.gz"
RIO_URL="https://github.com/rancher/rio/releases/download/${RIO_VERSION}/rio-linux-amd64"
HELM_URL="https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz"
DRONE_URL=""
fi
elif [[ $OSTYPE == "darwin"* ]]; then
KUBECTL_URL="https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/darwin/amd64/kubectl"
K3D_URL="https://github.com/rancher/k3d/releases/download/${K3D_VERSION}/k3d-darwin-amd64"
TKN_URL="https://github.com/tektoncd/cli/releases/download/${TEKTON_VERSION}/tkn_${TEKTON_VERSION:1}_Darwin_x86_64.tar.gz"
RIO_URL="https://github.com/rancher/rio/releases/download/${RIO_VERSION}/rio-darwin-amd64"
HELM_URL="https://get.helm.sh/helm-${HELM_VERSION}-darwin-amd64.tar.gz"
DRONE_URL=""
DISTROSHELL="ZSH"
fi
echo "Detected $DISTROSHELL on $OSTYPE"
}
prep_helm_repos() {
helm repo add jaegertracing https://jaegertracing.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add concourse https://concourse-charts.storage.googleapis.com
helm repo add traefik https://helm.traefik.io/traefik
helm repo add minio https://charts.min.io/
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
}
install_binaries() {
echo "Installing management binaries to `pwd`/bin"
if ! [[ -d "bin" ]]; then
mkdir bin
fi
export PATH=$PATH:`pwd`/bin
if ! [[ -f bin/kubectl ]]; then
echo $KUBECTL_URL
curl -L $KUBECTL_URL -o bin/kubectl
fi
if ! [[ -f bin/k3d ]]; then
curl -L $K3D_URL -o bin/k3d
fi
if ! [[ -f bin/rio ]]; then
curl -L $RIO_URL -o bin/rio
fi
if ! [[ -f bin/tkn ]]; then
if [[ "$DISTROSHELL" == "BASH" || "$DISTROSHELL" == "ZSH" ]]; then
curl -L $TKN_URL | tar xzv tkn
mv tkn bin/
elif [[ "$DISTROSHELL" == "WSL" || "$DISTROSHELL" == "MSYS" ]]; then
curl -L $TKN_URL -o tkn.zip
unzip tkn.zip tkn.exe
mv tkn.exe bin/tkn
rm tkn.zip
fi
fi
if ! [[ -f bin/helm ]]; then
if [[ "$DISTROSHELL" == "BASH" || $DISTROSHELL == "ZSH" ]]; then
if [[ "$DISTROSHELL" == "ZSH" ]]; then
DISTRI="darwin"
elif [[ "$DISTROSHELL" == "BASH" ]]; then
DISTRI="linux"
fi
curl -L $HELM_URL | tar xzv ${DISTRI}-amd64/helm
mv ${DISTRI}-amd64/helm bin/
rmdir ${DISTRI}-amd64
elif [[ "$DISTROSHELL" == "WSL" || "$DISTROSHELL" == "MSYS" ]]; then
curl -L $HELM_URL -o helm.zip
unzip helm.zip windows-amd64/helm.exe
mv windows-amd64/helm.exe bin/helm
rm -r helm.zip windows-amd64/
fi
fi
find ./bin -type f -exec chmod +x {} +
}
install_traefik() {
echo "Installing Traefik"
#We could also use the k3d built-in traefik helm-chart by removing the --no-deploy=traefik server-arg
#Upgrading traefik would be kind of a pain, since I don't know if they actually modified traefik in any way
#So we manage the ingress completely outside of k3d
kubectl apply -f ingress/traefik/rbac.yaml -f ingress/traefik/deployment.yaml -f ingress/traefik/dashboard.yaml
}
install_traefik2() {
echo "Installing Traefik2"
helm install traefik traefik/traefik
}
install_nginx() {
echo "Installing NGinX"
kubectl apply -f ingress/nginx/mandatory.yaml
}
install_tekton() {
echo "Installing Tekton-CD"
#Install Tekton
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
#Install Dashboard
kubectl apply -f https://github.com/tektoncd/dashboard/releases/download/$TEKTON_DASHBOARD_VERSION/tekton-dashboard-release.yaml
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f cd/tekton/${INGRESS}-ingress.yaml
fi
kubectl apply -f cd/tekton/sample-pipeline/k8s/svc-account.yaml \
-f cd/tekton/sample-pipeline/k8s/svc-credentials.yaml \
-f cd/tekton/sample-pipeline/tekton/build-task.yaml \
-f cd/tekton/sample-pipeline/tekton/deploy-task.yaml \
-f cd/tekton/sample-pipeline/tekton/git-task.yaml \
-f cd/tekton/sample-pipeline/tekton/pipeline.yaml
}
install_argocd() {
kubectl create namespace argocd
kubectl apply -n argocd -f cd/argocd/config.yaml \
-f cd/argocd/secrets.yaml \
-f cd/argocd/roles.yaml \
-f cd/argocd/deployment.yaml \
-f cd/argocd/service.yaml
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f cd/argocd/${INGRESS}-ingress.yaml
fi
}
install_drone() {
echo "Installing Drone CI"
echo "stub"
}
install_rio() {
localdomain=`dialog --inputbox "What local Domain do you want?" 0 0 "myrio" \
3>&1 1>&2 2>&3`
dialog --clear
echo "Generating cert and key for domain myrio"
openssl req -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout ${localdomain}.key -out ${localdomain}.crt -subj "/C=DE/ST=Bavaria/L=Nuremberg/O=DevOps/OU=IT Department/CN=${localdomain}"
echo "Installing Rancher RIO (without letsencrypt or rdns for local stuff)"
rio install --disable-features rdns,letsencrypt,gloo
echo "Create wildcard TLS secret for ${localdomain}"
kubectl -n rio-system create secret tls ${localdomain}-tls --cert=${localdomain}.crt --key=${localdomain}.key
sed "s/your.company.com/${localdomain}/g" cd/rio/clusterdomain.yaml | kubectl apply -f -
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f cd/rio/${INGRESS}-ingress.yaml
fi
}
install_rio_dashboard() {
echo "Installing Rancher RIO Dashboard (this might take a while)"
rio dashboard
}
install_istio() {
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=${ISTIO_VERSION} sh -
$PWD/istio-${ISTIO_VERSION}/bin/istioctl manifest apply --set profile=demo
cp $PWD/istio-${ISTIO_VERSION}/bin/istioctl $PWD/bin/
}
install_concourse() {
helm install concourse concourse/concourse
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f cd/concourse/${INGRESS}-ingress.yaml
fi
}
install_alertmanager() {
helm install alertmanager prometheus-community/alertmanager
}
install_prometheus() {
echo "Installing Prometheus"
# Create the namespace and CRDs, and then wait for them to be availble before creating the remaining resources
#kubectl create -f observability/prometheus/setup/
# Wait until the "servicemonitors" CRD is created. The message "No resources found" means success in this context.
#until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done
#kubectl create -f observability/prometheus/manifests/
helm install prometheus prometheus-community/prometheus -f observability/prometheus/values.yaml
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f observability/prometheus/${INGRESS}-ingress.yaml
fi
}
install_grafana() {
echo "Installing Grafana"
# kubectl apply -f observability/grafana/dashboard-cfgmap.yaml \
# -f observability/grafana/datasource-configMap.yaml \
# -f observability/grafana/deployment.yaml \
# -f observability/grafana/service.yaml
helm install grafana grafana/grafana -f observability/grafana/values.yaml
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f observability/grafana/${INGRESS}-ingress.yaml
fi
}
install_jaeger() {
# kubectl apply -f observability/jaeger/crd.yaml
# #Wait a sec, so you don't get "no matches for kind "Jaeger" in version "jaegertracing.io/v1"
# sleep 1
# kubectl apply -f observability/jaeger/service_account.yaml \
# -f observability/jaeger/role.yaml \
# -f observability/jaeger/role_binding.yaml \
# -f observability/jaeger/operator.yaml \
# -f observability/jaeger/cluster_role.yaml \
# -f observability/jaeger/cluster_role_binding.yaml \
# -f observability/jaeger/instance.yaml
helm install jaeger jaegertracing/jaeger -f observability/jaeger/values.yaml
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f observability/jaeger/${INGRESS}-ingress.yaml
fi
}
install_minio() {
# kubectl apply -f storage/minio/credentials-secret.yaml \
# -f storage/minio/operator.yaml \
# -f storage/minio/instance.yaml \
# -f storage/minio/service.yaml
kubectl create namespace minio
helm install --namespace minio --set rootUser=rootuser,rootPassword=rootpass123,replicas=1 --generate-name minio/minio
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f storage/minio/${INGRESS}-ingress.yaml
fi
}
install_cassandra() {
kubectl apply -f db/cassandra/service.yaml \
-f db/cassandra/deployment-stateful.yaml \
-f db/cassandra/deployment-cqlsh.yaml
}
start_k3d_cluster() {
if [[ $TOOLS == *"registry"* ]]; then
echo "The registry-feature is not supported in K3D 3.x as of yet."
echo "If you really need it, I recommend going back to 1.7.0"
#K3D_ARGS="$K3D_ARGS --enable-registry"
if [[ "$DISTROSHELL" == "BASH" || "$DISTROSHELL" == "ZSH" ]]; then
HOSTS_FILE_LOCATION="/etc/hosts"
elif [[ "$DISTROSHELL" == "WSL" || "$DISTROSHELL" == "MSYS" ]]; then
HOSTS_FILE_LOCATION="C:\\Windows\\system32\\drivers\\etc\\hosts"
fi
#echo "Things to do to use the local registry: "
#echo "1) Make sure to push your images to registry.local:5000/some/awesomeimage:tag"
#echo "2) Add \"127.0.0.1 registry.local\" to your hosts file at $HOSTS_FILE_LOCATION"
#echo "3) Add registry.local:5000 to your Docker Daemons insecure-registries array"
fi
if [[ $CICD == *"tekton"* ]]; then
mkdir -p $PWD/$K3D_MOUNT_DIR
K3D_ARGS="${K3D_ARGS} --volume $PWD/$K3D_MOUNT_DIR:/var/k3dshare/"
fi
echo "Starting k3d Cluster with args: $K3D_ARGS"
#Double Expansion with bash -c or you get a borked node filter error in your --k3s-arg
bash -c "k3d cluster create $K3D_ARGS"
echo "wait a bit for k3d to start up"
sleep 20
}
# This is technically deprecated, since K3D 3.x does it out of the box
patch_coredns() {
kubectl -n kube-system patch cm coredns --patch "$(sed "s/REGISTRY_IP/$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' /k3d-registry)/g" tools/registry/patch_coredns.yaml)"
}
config_k3d_cluster() {
echo "Configuring k3d cluster"
if [[ "$DISTROSHELL" == "WSL" ]]; then
echo "Need to create %USERPROFILE%/.kube/config, because somehow kubectl is now broken"
WINHOME=$(wslpath $(cmd.exe /c "<nul set /p=%UserProfile%" 2>/dev/null))
mkdir -p $WINHOME/.kube
k3d kubeconfig get dev > $WINHOME/.kube/config_k3d
export KUBECONFIG=$WINHOME/.kube/config_k3d
elif [[ "$DISTROSHELL" == "BASH" || "$DISTROSHELL" == "ZSH" || "$DISTROSHELL" == "WSL2" ]]; then
mkdir -p ~/.kube/
k3d kubeconfig get dev > ~/.kube/config_k3d
export KUBECONFIG=~/.kube/config_k3d
elif [[ "$DISTROSHELL" == "MSYS" ]]; then
echo "I hate MinGW, GitBash, MSYS, so this is an empty stub as of now"
#echo "Converting paths to POSIX, because derp"
#export KUBECONFIG=$(k3d kubeconfig get dev | sed 's_\\_\/_g' | sed 's_C:_/c_')
fi
#if [[ $TOOLS == *"registry"* ]]; then
# patch_coredns
#fi
}
install_k8s_dashboard() {
helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard
if [[ ! "$INGRESS" == "none" ]]; then
kubectl apply -f k8s-dashboard/${INGRESS}-ingress.yaml
fi
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
}
install_ci() {
if [[ $CICD == "tekton" ]]; then
install_tekton
elif [[ $CICD == "rio" ]]; then
install_rio
elif [[ $CICD == "argocd" ]]; then
install_argocd
elif [[ $CICD == "drone" ]]; then
install_drone
elif [[ $CICD == "concourse" ]]; then
install_concourse
fi
}
install_ingress() {
if [[ $INGRESS == "nginx" ]]; then
install_nginx
elif [[ $INGRESS == "traefik" ]]; then
install_traefik
elif [[ $INGRESS == "traefik2" ]]; then
install_traefik2
elif [[ $INGRESS == "istio" || $TOOLS == *"istio"* ]]; then
install_istio
fi
}
install_tools() {
if [[ ! -z $TOOLS ]]; then
kubectl create namespace monitoring
fi
if [[ $TOOLS == *"grafana"* ]]; then
install_grafana
fi
if [[ $TOOLS == *"prometheus"* ]]; then
install_prometheus
fi
if [[ $TOOLS == *"jaeger"* ]]; then
install_jaeger
fi
if [[ $TOOLS == *"minio"* ]]; then
install_minio
fi
if [[ $TOOLS == *"k8s-dashboard"* ]]; then
install_k8s_dashboard
fi
if [[ $TOOLS == *"rio-dashboard"* ]]; then
install_rio_dashboard
fi
if [[ $TOOLS == *"alertmanager"* ]]; then
install_alertmanager
fi
}
install_db() {
if [[ ! "$DB" == "none" ]]; then
kubectl create namespace db
if [[ "$DB" == "cassandra" ]]; then
install_cassandra
fi
fi
}
verify_binaries() {
echo "Verifying installed binaries"
kubectl version
tkn version
k3d --version
rio --version
}
notify_user() {
echo "Now export the following lines and you are good to go!"
echo 'export PATH=$PATH:`pwd`/bin'
echo 'source <(kubectl completion bash)'
if [[ "$DISTROSHELL" == "BASH" ]]; then
echo "export KUBECONFIG=~/.kube/config_k3d"
fi
echo ""
echo ""
echo ""
echo $'To access apps behind your ingress, run the following command: '
if [[ $INGRESS == "nginx" ]]; then
echo $'kubectl port-forward -n ingress-nginx `kubectl get pods -n ingress-nginx --template \'{{range .items}}{{.metadata.name}}{{\"\\n\"}}{{end}}\' | grep \"^nginx-ingress\"` 8080:80 8443:443 &'
elif [[ $INGRESS == "traefik" ]]; then
echo $'kubectl port-forward -n kube-system `kubectl get pods -n kube-system --template \'{{range .items}}{{.metadata.name}}{{\"\\n\"}}{{end}}\' | grep \"^traefik\"` 8080:80 8443:443 8081:8080 &'
echo "Traefik Dashboard is available at http://localhost:8080/traefik"
elif [[ $INGRESS == "traefik2" ]]; then
echo $'kubectl port-forward -n kube-system `kubectl get pods -n kube-system --template \'{{range .items}}{{.metadata.name}}{{\"\\n\"}}{{end}}\' | grep \"^traefik\"` 8080:80 8443:443 8081:8080 &'
echo "Traefik2 Dashboard is available at http://localhost:8081/dashboard/"
elif [[ $INGRESS == "istio" ]]; then
echo $'kubectl port-forward -n kube-system `kubectl get pods -n istio-system --template \'{{range .items}}{{.metadata.name}}{{\"\\n\"}}{{end}}\' | grep \"^istio-ingressgateway\"` 8080:80 8443:443 8081:8080 &'
echo "To access the various Istio Dashboards, use $PWD/istio-${ISTIO_VERSION}/bin/istioctl dashboard, or kubectl port-forward like the following prometheus example."
fi
if [[ $CICD == "tekton" ]]; then
echo "Tekton Dashboard is available at http://localhost:8080/tekton/"
elif [[ $CICD == "argocd" ]]; then
echo "ArgoCD is available at http://localhost:8080/argocd"
echo "The initial login credentials are admin:$(kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2)"
elif [[ $CICD == "concourse" ]]; then
echo "Concourse is not playing along right now, it seems to work only on a root path. Nothing another port-forward can't fix!"
echo $'kubectl port-forward `kubectl get pods --template \'{{range .items}}{{.metadata.name}}{{\"\\n\"}}{{end}}\' | grep \"^concourse-web\"` <port>:8080 &'
echo "The login for concourse is test:test"
fi
if [[ $DB == "cassandra" ]]; then
echo ""
echo "You can check if cassandra is ready with this command:"
echo $'kubectl rollout status statefulset/cassandra -n db'
echo "To connect to your cassandra via cqlsh, just use the following command:"
echo $'kubectl -n db exec -ti $(kubectl get pods -n db | grep cqlsh) -- cqlsh cassandra.db.svc.cluster.local'
echo ""
fi
echo "K8S Dashboard is available at https://localhost:8081/dashboard/"
}