This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
krib-dashboard.sh.tmpl
102 lines (85 loc) · 3.04 KB
/
krib-dashboard.sh.tmpl
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
#!/usr/bin/env bash
# Kubernetes Rebar Immutable Boot (KRIB) Kubeadm Installer
set -e
# Get access and who we are.
{{template "setup.tmpl" .}}
{{if .ParamExists "krib/cluster-profile" -}}
CLUSTER_PROFILE={{.Param "krib/cluster-profile"}}
PROFILE_TOKEN={{.GenerateProfileToken (.Param "krib/cluster-profile") 7200}}
{{else -}}
xiterr 1 "Missing krib/cluster-profile on the machine!"
{{end -}}
{{template "krib-lib.sh.tmpl" .}}
export RS_UUID="{{.Machine.UUID}}"
{{ if eq (.Param "krib/dashboard-enabled") true -}}
cloneHeapster() {
if [ -d heapster ]; then
cd heapster || return 1
git reset --hard HEAD || return 1
git pull || return 1
else
git clone --depth 1 https://github.com/kubernetes/heapster.git || return 1
fi
}
echo "Start Dashboard"
MASTER_INDEX=$(find_me $KRIB_MASTERS_PARAM "Uuid" $RS_UUID)
MASTER_COUNT={{.Param "krib/cluster-master-count"}}
if [[ $MASTER_INDEX == 0 ]] ; then
export KUBECONFIG=/etc/kubernetes/admin.conf
if ! which rsync ; then
install rsync
fi
if ! which git ; then
install git
fi
if ! which wget ; then
install wget
fi
wget -O /tmp/kubernetes-dashboard.yaml {{ .Param "krib/dashboard-config" }}
OPWD=$(pwd)
cd /tmp
if ! cloneHeapster; then
rm -rf heapster
cloneHeapster
fi
cd $OPWD
sed -i 's/name: system:heapster/name: cluster-admin/' /tmp/heapster/deploy/kube-config/rbac/heapster-rbac.yaml
sed -i 's#source=kubernetes:https://kubernetes.default$#source=kubernetes:https://kubernetes.default?useServiceAccount=true\&kubeletHttps=true\&kubeletPort=10250\&insecure=true#' /tmp/heapster/deploy/kube-config/influxdb/heapster.yaml
mkdir -p /root/setup/dashboard
cp /tmp/kubernetes-dashboard.yaml /root/setup/dashboard/kubernetes-dashboard.yaml
cat > /root/setup/dashboard/dashboard-serviceaccount.yaml << EOFSA
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
EOFSA
cat >/root/setup/dashboard/dashboard-admin.yaml <<EOFDA
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
EOFDA
cp -r /tmp/heapster /root/setup/dashboard
kubectl apply -f /root/setup/dashboard/kubernetes-dashboard.yaml
kubectl apply -f /root/setup/dashboard/dashboard-serviceaccount.yaml
kubectl apply -f /root/setup/dashboard/dashboard-admin.yaml
kubectl apply -f /root/setup/dashboard/heapster/deploy/kube-config/influxdb/
kubectl apply -f /root/setup/dashboard/heapster/deploy/kube-config/rbac/heapster-rbac.yaml
kubectl scale --replicas=$MASTER_COUNT -n kube-system deployment/kubernetes-dashboard
kubectl scale --replicas=$MASTER_COUNT -n kube-system deployment/heapster
kubectl scale --replicas=$MASTER_COUNT -n kube-system deployment/monitoring-influxdb
rm -rf /root/setup /tmp/heapster
fi
echo "Finished successfully"
{{end -}}
drpcli machines update $RS_UUID "{\"Meta\":{\"color\":\"green\", \"icon\": \"anchor\"}}" | jq .Meta
exit 0