forked from Altinity/clickhouse-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-prometheus.sh
executable file
·89 lines (77 loc) · 4.66 KB
/
create-prometheus.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
#!/bin/bash
echo "External value for \$PROMETHEUS_NAMESPACE=$PROMETHEUS_NAMESPACE"
echo "External value for \$OPERATOR_NAMESPACE=$OPERATOR_NAMESPACE"
echo "External value for \$VALIDATE_YAML=$VALIDATE_YAML"
export PROMETHEUS_NAMESPACE="${PROMETHEUS_NAMESPACE:-prometheus}"
export OPERATOR_NAMESPACE="${OPERATOR_NAMESPACE:-kube-system}"
export PROMETHEUS_OPERATOR_BRANCH="${PROMETHEUS_OPERATOR_BRANCH:-release-0.43}"
export ALERT_MANAGER_EXTERNAL_URL="${ALERT_MANAGER_EXTERNAL_URL:-http://localhost:9093}"
# Possible values for "validate yaml" are values from --validate=XXX kubectl option. They are true/false ATM
export VALIDATE_YAML="${VALIDATE_YAML:-true}"
CUR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
echo "OPTIONS"
echo "Setup Prometheus into \$PROMETHEUS_NAMESPACE=${PROMETHEUS_NAMESPACE} namespace"
echo "Expecting operator in \$OPERATOR_NAMESPACE=${OPERATOR_NAMESPACE} namespace"
echo "Validate .yaml file \$VALIDATE_YAML=${VALIDATE_YAML}"
echo ""
echo "!!! IMPORTANT !!!"
echo "If you do not agree with specified options, press ctrl-c now"
sleep 10
echo "Apply options now..."
# Let's setup all prometheus-related stuff into dedicated namespace called "prometheus"
kubectl create namespace "${PROMETHEUS_NAMESPACE}" || true
BASE_PATH="https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/${PROMETHEUS_OPERATOR_BRANCH}"
echo "Create prometheus-operator's CRDs"
CRD_PATH="${BASE_PATH}/example/prometheus-operator-crd"
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${CRD_PATH}"/monitoring.coreos.com_alertmanagers.yaml
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${CRD_PATH}"/monitoring.coreos.com_podmonitors.yaml
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${CRD_PATH}"/monitoring.coreos.com_prometheuses.yaml
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${CRD_PATH}"/monitoring.coreos.com_prometheusrules.yaml
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${CRD_PATH}"/monitoring.coreos.com_servicemonitors.yaml
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${CRD_PATH}"/monitoring.coreos.com_thanosrulers.yaml
echo "Setup prometheus-operator into '${PROMETHEUS_NAMESPACE}' namespace."
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f <( \
wget -qO- "${BASE_PATH}"/bundle.yaml | \
PROMETHEUS_NAMESPACE=${PROMETHEUS_NAMESPACE} sed "s/namespace: default/namespace: ${PROMETHEUS_NAMESPACE}/" \
)
echo "Setup RBAC"
RBAC_PATH="${BASE_PATH}/example/rbac/prometheus"
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f <( \
wget -qO- "${RBAC_PATH}"/prometheus-cluster-role-binding.yaml | \
PROMETHEUS_NAMESPACE=${PROMETHEUS_NAMESPACE} sed "s/namespace: default/namespace: ${PROMETHEUS_NAMESPACE}/" \
)
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${RBAC_PATH}"/prometheus-cluster-role.yaml
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f \
"${RBAC_PATH}"/prometheus-service-account.yaml
echo "Setup Prometheus instance via prometheus-operator into '${PROMETHEUS_NAMESPACE}' namespace"
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f <( \
cat "${CUR_DIR}/prometheus-template.yaml" | PROMETHEUS_NAMESPACE=${PROMETHEUS_NAMESPACE} envsubst \
)
echo "Setup Prometheus -> AlertManager -> Slack integration"
if [[ ! -f ${CUR_DIR}/prometheus-sensitive-data.sh ]]; then
echo "!!! IMPORTANT !!!"
echo "There is no ${CUR_DIR}/prometheus-sensitive-data.sh file found "
echo "This means that there will be no Prometheus -> AlertManager -> Slack integration"
echo "If you do not agree with specified options and would like to have this integration, press ctrl-c now and"
echo "please copy ${CUR_DIR}/prometheus-sensitive-data.example.sh to ${CUR_DIR}/prometheus-sensitive-data.sh"
echo "and edit it according to Slack documentation https://api.slack.com/incoming-webhooks"
sleep 10
echo "Skip Prometheus -> alertmanager -> Slack integration"
else
source "${CUR_DIR}/prometheus-sensitive-data.sh"
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f <( \
cat "${CUR_DIR}/prometheus-alertmanager-template.yaml" | \
envsubst \
)
for rules_file in "${CUR_DIR}"/prometheus-alert-rules*.yaml; do
kubectl --namespace="${PROMETHEUS_NAMESPACE}" apply --validate="${VALIDATE_YAML}" -f "${rules_file}"
done
fi
echo "Add is done"