-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_k8s_monitor.sh
181 lines (160 loc) · 7.54 KB
/
install_k8s_monitor.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
#!/bin/bash -e
if [ -n "$(echo $REPO | grep ^http)" ]
then
source <(curl -Ls ${REPO}/env_function.sh)
else
source ${REPO}/env_function.sh
fi
helm repo add bitnami https://charts.bitnami.com/bitnami
WORK_DIR=${WORK_DIR:-`pwd`}
namespace=`getarg namespace $@ 2>/dev/null`
namespace=${namespace:-"monitor-system"}
storage_class=`getarg storage_class $@ 2>/dev/null`
storage_class=${storage_class:-""}
password=`getarg password $@ 2>/dev/null`
password=${password:-"Pa44VV0rd14VVrOng"}
ingress_class=`getarg ingress_class $@ 2>/dev/null`
ingress_class=${ingress_class:-higress}
db_namespace=`getarg db_namespace $@ 2>/dev/null`
db_namespace=${db_namespace:-db-system}
vm_namespace=`getarg vm_namespace $@ 2>/dev/null`
vm_namespace=${vm_namespace:-${db_namespace}}
es_namespace=`getarg es_namespace $@ 2>/dev/null`
es_namespace=${es_namespace:-${db_namespace}}
es_protocol=`getarg es_protocol $@ 2>/dev/null`
es_host=`getarg es_host $@ 2>/dev/null`
es_user=`getarg es_user $@ 2>/dev/null`
es_password=`getarg es_password $@ 2>/dev/null`
es_password=${es_password:-${password}}
## install kibana
# https://github.com/bitnami/charts/tree/main/bitnami/kibana/#installing-the-chart
if [ ! -f "$es_password" ]; then
es_password=$(kubectl get secret elasticsearch -n ${es_namespace} -o jsonpath='{.data.elasticsearch-password}' | base64 --decode)
fi
kubectl create namespace ${namespace} 2>/dev/null
kubectl delete secret kibana-admin -n ${namespace} 2>/dev/null
kubectl create secret generic kibana-admin -n ${namespace} \
--from-literal=kibana-password=${es_password} \
--from-literal=elasticsearch-password=${es_password}
helm upgrade --install kibana bitnami/kibana \
--set image.registry=${bitnami_image_registry} \
--set global.storageClass=${storage_class} \
--set elasticsearch.hosts[0]=${es_host:-elasticsearch.${es_namespace}.svc} \
--set elasticsearch.port="9200" \
--set elasticsearch.security.auth.enabled=true \
--set elasticsearch.security.auth.kibanaPassword="${es_password}" \
--set elasticsearch.security.auth.existingSecret="kibana-admin" \
--set elasticsearch.security.auth.createSystemUser=true \
--set elasticsearch.security.auth.elasticsearchPasswordSecret="kibana-admin" \
-n ${namespace} --create-namespace
# helm uninstall kibana -n ${namespace}
kibana_route_rule=`getarg kibana_route_rule $@`
kibana_route_rule=${kibana_route_rule:-localhost}
srv_name=$(kubectl get service -n ${namespace} | grep kibana | awk '{print $1}')
src_port=$(kubectl get services -n ${namespace} $srv_name -o jsonpath="{.spec.ports[0].port}")
install_ingress_rule \
--name kibana \
--namespace ${namespace} \
--ingress_class ${ingress_class} \
--service_name $srv_name \
--service_port $src_port \
--domain ${kibana_route_rule}
## install prometheus
# https://github.com/bitnami/charts/tree/main/bitnami/prometheus/#installing-the-chart
# https://docs.victoriametrics.com/url-examples/ # remote write to vm
helm upgrade --install prometheus bitnami/prometheus \
--set image.registry=${bitnami_image_registry} \
--set global.storageClass=${storage_class} \
--set admin.password=${password} \
--set alertmanager.enabled=false \
--set server.enableAdminAPI=true \
--set server.service.type=ClusterIP \
--set server.remoteWrite[0].url="http://victoria-metrics-cluster-vminsert.${vm_namespace}.svc:8480//insert/0/prometheus/api/v1/import/prometheus" \
--set server.extraScrapeConfigs[0].job_name=higress \
--set server.extraScrapeConfigs[0].kubernetes_sd_configs[0].role=endpoints \
--set server.extraScrapeConfigs[0].kubernetes_sd_configs[0].namespaces.names='{higress-system,monitor-system}' \
--set server.extraScrapeConfigs[0].relabel_configs[0].regex='__meta_kubernetes_pod_label_(.+)' \
--set server.extraScrapeConfigs[0].relabel_configs[0].replacement='$1' \
--set server.extraScrapeConfigs[0].relabel_configs[0].action='labelmap' \
-n ${namespace} --create-namespace
# helm uninstall prometheus -n ${namespace}
prometheus_route_rule=`getarg prometheus_route_rule $@`
prometheus_route_rule=${prometheus_route_rule:-'prometheus.localhost'}
srv_name=$(kubectl get service -n ${namespace} | grep prometheus | awk '{print $1}')
src_port=$(kubectl get services -n ${namespace} $srv_name -o jsonpath="{.spec.ports[0].port}")
install_ingress_rule \
--name prometheus \
--namespace ${namespace} \
--ingress_class ${ingress_class} \
--service_name $srv_name \
--service_port $src_port \
--domain ${prometheus_route_rule}
## install grafana
# https://github.com/bitnami/charts/tree/main/bitnami/grafana/#installing-the-chart
helm upgrade --install grafana bitnami/grafana \
--set image.registry=${bitnami_image_registry} \
--set global.storageClass=${storage_class} \
--set admin.password=${password} \
--set grafana.extraEnvVars[0].name=GF_SECURITY_COOKIE_SECURE \
--set-string grafana.extraEnvVars[0].value=true \
--set grafana.extraEnvVars[1].name=GF_SECURITY_COOKIE_SAMESITE \
--set-string grafana.extraEnvVars[1].value=none \
--set grafana.extraEnvVars[2].name=GF_SECURITY_ALLOW_EMBEDDING \
--set-string grafana.extraEnvVars[2].value=true \
-n ${namespace} --create-namespace
# helm uninstall grafana -n ${namespace}
grafana_route_rule=`getarg grafana_route_rule $@`
grafana_route_rule=${grafana_route_rule:-'grafana.localhost'}
srv_name=$(kubectl get service -n ${namespace} | grep grafana | awk '{print $1}')
src_port=$(kubectl get services -n ${namespace} $srv_name -o jsonpath="{.spec.ports[0].port}")
install_ingress_rule \
--name grafana \
--namespace ${namespace} \
--ingress_class ${ingress_class} \
--service_name $srv_name \
--service_port $src_port \
--domain ${grafana_route_rule}
## install skywalking
# https://github.com/apache/skywalking-helm
# SW_ES_USER,SW_ES_PASSWORD,SW_STORAGE_ES_HTTP_PROTOCOL,SW_SW_STORAGE_ES_SSL_JKS_PATH,SW_SW_STORAGE_ES_SSL_JKS_PASS
git clone ${GHPROXY}https://github.com/apache/skywalking-helm
cd skywalking-helm
sed -i '1,31!d' chart/skywalking/Chart.yaml # remove dependences
helm upgrade --install skywalking chart/skywalking \
--version 4.7.0 \
--set ui.image.repository=docker.io/apache/skywalking-ui \
--set ui.image.tag=10.1.0 \
--set oap.image.repository=docker.io/apache/skywalking-oap-server \
--set oap.image.tag=10.1.0 \
--set oap.replicas=1 \
--set elasticsearch.enabled=false \
--set postgresql.enabled=false \
--set banyandb.enabled=false \
--set oap.storageType=elasticsearch \
--set elasticsearch.replicas=1 \
--set elasticsearch.config.protocol=${es_protocol:-http} \
--set elasticsearch.config.host=${es_host:-elasticsearch.${es_namespace}.svc} \
--set elasticsearch.config.user="${es_user:-elastic}" \
--set elasticsearch.config.password="${es_password}" \
--set elasticsearch.persistence.enabled=true \
--set elasticsearch.antiAffinity="" \
--set elasticsearch.antiAffinityTopologyKey="" \
--set satellite.enabled=false \
-n ${namespace} --create-namespace
cd $WORK_DIR
rm -rf skywalking-helm
# helm uninstall skywalking -n ${namespace}
skywalking_route_rule=`getarg skywalking_route_rule $@ 2>/dev/null`
skywalking_route_rule=${skywalking_route_rule:-'skywalking.localhost'}
srv_name=$(kubectl get service -n ${namespace} | grep skywalking | grep ui | awk '{print $1}')
src_port=$(kubectl get services -n ${namespace} $srv_name -o jsonpath="{.spec.ports[0].port}")
install_ingress_rule \
--name skywalking \
--namespace ${namespace} \
--ingress_class ${ingress_class} \
--service_name $srv_name \
--service_port $src_port \
--domain ${skywalking_route_rule}
echo "---------------------------------------------------------------------"
echo "done"
echo "---------------------------------------------------------------------"