-
Notifications
You must be signed in to change notification settings - Fork 2
/
microk8s-kube-bench.sh
executable file
·72 lines (54 loc) · 2.13 KB
/
microk8s-kube-bench.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
#!/bin/bash
set -e
trap 'catch $? $LINENO' EXIT
catch() {
if [ "$1" != "0" ]; then
echo "Error $1 occurred on line $2"
fi
}
if [[ -z ${MK8S_INSTALL+x} ]] ; then export MK8S_INSTALL='false' ; fi ; echo "mk8s install: $MK8S_INSTALL"
if [[ -z ${MK8S_VERSION+x} ]] ; then export MK8S_VERSION='1.19' ; fi ; echo "mk8s version: $MK8S_VERSION"
if [[ -z ${MK8S_KUBE_DIR+x} ]] ; then export MK8S_KUBE_DIR='/.kube' ; fi ; echo "mk8s kube dir: $MK8S_KUBE_DIR"
if [[ -z ${KUBE_BENCH_DEPLOY+x} ]] ; then export KUBE_BENCH_DEPLOY='true' ; fi ; echo "kube-bench deploy: $KUBE_BENCH_DEPLOY"
if [[ "$MK8S_INSTALL" == 'true' ]]
then
#make sure of greenfield
[[ ! -d "$MK8S_KUBE_DIR" ]]
echo -e "\n### installing microk8s & add-ons: "
snap install microk8s --classic --channel="$MK8S_VERSION"
snap list
snap info microk8s
microk8s status --wait-ready
microk8s kubectl get nodes
microk8s kubectl get services
[[ -d "$MK8S_KUBE_DIR" ]]
fi
microk8s status | grep 'microk8s is running'
microk8s config view
if [[ "$KUBE_BENCH_DEPLOY" == 'true' ]]
then
echo -e "\n### deploying kube-bench: "
microk8s kubectl apply -f "https://raw.githubusercontent.com/aquasecurity/kube-bench/master/job.yaml"
microk8s kubectl get jobs
microk8s kubectl get pods
while [[ ! $(microk8s kubectl get pods | grep 'kube-bench') == *'Completed'* ]]
do
echo -e "waiting: $(microk8s kubectl get pods | grep 'kube-bench')"
sleep 5s
done
echo -e "\n### final status:"
microk8s kubectl get jobs
microk8s kubectl get pods
echo -e "\n### pod logs:"
POD=$(microk8s kubectl get pods | grep 'kube-bench' | grep 'Completed' | awk '{print $1}')
echo "kube-bench pod: $POD"
microk8s kubectl logs "$POD"
cat README.template.md > README.md
echo '```' >> README.md
echo "execution date: $(date --utc)" >> README.md
echo " " >> README.md
echo "microk8s snap version: $(snap list | grep 'microk8s')" >> README.md
echo " " >> README.md
microk8s kubectl logs "$POD" >> README.md
echo '```' >> README.md
fi