-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.sh
executable file
·75 lines (67 loc) · 1.74 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
#!/bin/bash
set -e
NAMESPACE=${NAMESPACE:-"nezha-demo"}
start() {
kubectl create ns ${NAMESPACE} || true
# create nginx config as a configmap
kubectl create -n ${NAMESPACE} configmap nginx-proxy --from-file=nginx.conf || true
# create nginx and svc
kubectl apply -n ${NAMESPACE} -f nginx.yaml
# create csr
../../deploy/create-signed-crt.sh
# create webhook svc
CA_BUNDLE=$(kubectl get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' | base64 | tr -d '\n')
cat ../../deploy/mutatingwebhook.yaml | sed -e "s|\${CA_BUNDLE}|${CA_BUNDLE}|g" | kubectl apply -f -
# patch host aliases
SVC=$(kubectl get svc -n ${NAMESPACE} proxy-cache -o jsonpath={.spec.clusterIP})
SERVERS=$(grep server_name nginx.conf |tr -d ';' |awk '{print $2}')
file=$(mktemp temp.XXX.yaml)
cat > ${file} <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: hostaliases-config
data:
config: |
- name: dataset
app: app.kubernetes.io/deploy-manager
label: ksonnet
hostAliases:
- ip: "${SVC}"
hostnames:
EOF
for s in ${SERVERS}
do
echo " - \"${s}\"" >> ${file}
done
kubectl apply -f ${file}
rm ${file}
}
clean() {
kubectl delete -f ../../deploy/mutatingwebhook.yaml
kubectl delete -n ${NAMESPACE} -f nginx.yaml
kubectl delete -n ${NAMESPACE} configmap nginx-proxy
kubectl delete ns ${NAMESPACE}
exit 0
}
usage() {
cat <<EOF
usage: ${0} start|clean
EOF
exit 1
}
while [[ $# -gt 0 ]]
do
case ${1} in
start)
start
;;
clean)
clean
;;
*)
usage
;;
esac
shift
done