forked from fabianlee/k3s-cluster-kvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.sh
executable file
·338 lines (275 loc) · 7.99 KB
/
menu.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
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
#!/bin/bash
#
# menu to show available actions
#
BIN_DIR=$(dirname ${BASH_SOURCE[0]})
cd $BIN_DIR
# visual marker for task
declare -A done_status
# BASH does not support multi-dimensional/complex datastructures
# 1st column = action
# 2nd column = description
menu_items=(
"prereq,Prerequisites for OS, pip, Ansible"
"sshkeypair,Create SSH keypair for guest OS logins"
"tf,Create local KVM guest VMs using terraform"
"ansibleping,Verify that ansible can reach guest VMS"
"ssh,Manual ssh into guest VMs"
""
"k3s-prereq,prereq OS package, settings, binaries"
"k3s,Deploy k3s control plane and workers"
"k3s-post,k3s post configuration of cluster"
""
"metallb,Configure MetalLB to provide IP addresses to LB"
"certs,Create certs and load TLS secret into cluster"
""
"hello,Deploys hello app to /myhello/ and /myhello2/"
""
"nginx,Deploy NGINX Ingress at load balancer IP"
"nginx-test,Test primary and secondary NGINX Ingress"
""
"istio,Deploy Istio ingress gateway at load balancer IP"
"istio-test,Test primary and secondary Istio gateways"
""
"nfs-host,Create /data/nfs1 on Ansible orchestrator host"
"nfs-sc,Install nfs dynamic provisioner and StorageClass"
""
"mailhog,Deploy in-cluster SMTP server for mail alerts"
"prometheus,Deploy community kube-prometheus-stack with helm3"
)
function showMenu() {
echo ""
echo ""
echo "==========================================================================="
echo " MAIN MENU"
echo "==========================================================================="
echo ""
for menu_item in "${menu_items[@]}"; do
# skip empty lines
[ -n "$menu_item" ] || { printf "\n"; continue; }
menu_id=$(echo $menu_item | cut -d, -f1)
# eval done so that embedded variables get evaluated (e.g. MYKUBECONFIG)
label=$(eval echo $menu_item | cut -d, -f2-)
printf "%-16s %-60s %-12s\n" "$menu_id" "$label" "${done_status[$menu_id]}"
done
echo ""
} # showMenu
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
NC='\033[0m'
NF='\033[0m'
function echoGreen() {
echo -e "${GREEN}$1${NC}"
}
function echoRed() {
echo -e "${RED}$1${NC}"
}
function echoYellow() {
echo -e "${YELLOW}$1${NC}"
}
function ensure_binary() {
binary="$1"
install_instructions="$2"
binpath=$(which $binary)
if [ -z "$binpath" ]; then
echo "ERROR you must install $binary before running this wizard"
echo "$install_instructions"
exit 1
fi
}
function check_prerequisites() {
# make sure binaries are installed
ensure_binary kubectl "install https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/"
ensure_binary terraform "install https://fabianlee.org/2021/05/30/terraform-installing-terraform-manually-on-ubuntu/"
ensure_binary ansible "install https://fabianlee.org/2021/05/31/ansible-installing-the-latest-ansible-on-ubuntu/"
ensure_binary make "run 'sudo apt install make'"
# show binary versions
# on apt, can be upgraded with 'sudo apt install --only-upgrade google-cloud-sdk -y'
kubectl version --short 2>/dev/null
terraform --version | head -n 1
ansible --version | head -n1
make --version | head -n1
echo ""
} # check_prerequisites
###### MAIN ###########################################
# if kubeconfig optionally specified on command line
[ -n "$KUBECONFIG" ] || export KUBECONFIG="/tmp/kubeadm-kubeconfig"
check_prerequisites "$@"
# loop where user can select menu items
lastAnswer=""
answer=""
while [ 1 == 1 ]; do
showMenu
test -t 0
if [ ! -z $lastAnswer ]; then echo "Last action was '${lastAnswer}'"; fi
read -p "Which action (q to quit) ? " answer
echo ""
case $answer in
prereq)
set -x
ansible-playbook install_dependencies.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
sshkeypair)
cd tf-libvirt
set -x
if [ ! -f id_rsa ]; then
ssh-keygen -t rsa -b 4096 -f id_rsa -C tf-libvirt -N "" -q
else
echoGreen "SKIP SSH keypair for guest VMs already exists"
fi
retVal=$?
cd ..
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
tf)
set -x
ansible-playbook playbook_terraform_kvm.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
ansibleping)
set -x
ansible -m ping all
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
ssh)
retVal=0
echo "1. k3s-1"
echo "2. k3s-2"
echo "3. k32-3"
echo ""
read -p "ssh into which jumpbox ? " which_guest
case $which_guest in
1) guestvm=192.168.122.213
;;
2) guestvm=192.168.122.214
;;
3) guestvm=192.168.122.215
;;
*)
echo "ERROR did not recognize which $which_guest, valid choices 1-3"
retVal=1
;;
esac
set -x
ssh -i tf-libvirt/id_rsa ubuntu@${guestvm}
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
k3s-prereq)
set -x
ansible-playbook playbook_k3s_prereq.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
k3s)
set -x
ansible-playbook playbook_k3s.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
k3s-post)
set -x
ansible-playbook playbook_k3s_post.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
metallb)
set -x
ansible-playbook playbook_metallb.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
certs)
set -x
ansible-playbook playbook_certs.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
hello)
set -x
ansible-playbook playbook_hello.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
nginx)
set -x
ansible-playbook playbook_nginx.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
nginx-test)
set -x
ansible-playbook playbook_nginx_test.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
istio)
set -x
ansible-playbook playbook_istio.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
istio-test)
set -x
ansible-playbook playbook_istio_test.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
nfs-host)
set -x
prereq/create_host_nfs.sh
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
nfs-sc)
set -x
ansible-playbook playbook_nfs_helm_sc.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
mailhog)
set -x
ansible-playbook playbook_mailhog.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
prometheus)
set -x
ansible-playbook playbook_prometheus_helm.yml
retVal=$?
set +x
[ $retVal -eq 0 ] && done_status[$answer]="OK" || done_status[$answer]="ERR"
;;
q|quit|0)
echo "QUITTING"
exit 0;;
*)
echoRed "ERROR that is not one of the options, $answer";;
esac
lastAnswer=$answer
echo "press <ENTER> to continue..."
read -p "" foo
done