For `--dry-run` to work with kubectl a Kubernetes cluster's apiserver is actually used, which is unnecessary for generating these manifests. This approach also allows further customization, such as adding labels to the generated manifests.
48 lines
1.5 KiB
Bash
Executable File
48 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
if [ -z "${KUBECONFIG}" ]; then
|
|
export KUBECONFIG=~/.kube/config
|
|
fi
|
|
|
|
if [ -z "${NAMESPACE}" ]; then
|
|
NAMESPACE=monitoring
|
|
fi
|
|
|
|
kubectl create namespace "$NAMESPACE"
|
|
|
|
kctl() {
|
|
kubectl --namespace "$NAMESPACE" "$@"
|
|
}
|
|
|
|
kctl apply -f manifests/prometheus-operator.yaml
|
|
|
|
# Wait for TPRs to be ready.
|
|
printf "Waiting for Operator to register third party objects..."
|
|
until kctl get servicemonitor > /dev/null 2>&1; do sleep 1; printf "."; done
|
|
until kctl get prometheus > /dev/null 2>&1; do sleep 1; printf "."; done
|
|
until kctl get alertmanager > /dev/null 2>&1; do sleep 1; printf "."; done
|
|
echo "done!"
|
|
|
|
kctl apply -f manifests/exporters
|
|
kctl apply -f manifests/grafana
|
|
|
|
kctl apply -f manifests/prometheus/prometheus-k8s-rules.yaml
|
|
kctl apply -f manifests/prometheus/prometheus-k8s-service.yaml
|
|
|
|
kctl apply -f manifests/alertmanager/alertmanager-config.yaml
|
|
kctl apply -f manifests/alertmanager/alertmanager-service.yaml
|
|
|
|
# unfortunately statefulsets cannot be changed except for their replica count
|
|
# so we need to make sure that the rule files are created before we create the
|
|
# prometheus resource so it can properly discover the rule files when creating
|
|
# the statefulset
|
|
sleep 5
|
|
|
|
# `kubectl apply` is currently not working for third party resources so we are
|
|
# using `kubectl create` here for the time being.
|
|
# (https://github.com/kubernetes/kubernetes/issues/29542)
|
|
kctl create -f manifests/prometheus/prometheus-k8s-servicemonitors.yaml
|
|
kctl create -f manifests/prometheus/prometheus-k8s.yaml
|
|
kctl create -f manifests/alertmanager/alertmanager.yaml
|
|
|