Remove old manifests and replace with jsonnet build

This commit is contained in:
Frederic Branczyk
2018-04-10 10:51:00 +02:00
parent d8692794a9
commit 507617e150
127 changed files with 6332 additions and 8494 deletions

View File

@@ -1,40 +1,24 @@
#!/usr/bin/env bash
if [ -z "${KUBECONFIG}" ]; then
export KUBECONFIG=~/.kube/config
fi
manifest_prefix=${1-.}
# CAUTION - setting NAMESPACE will deploy most components to the given namespace
# however some are hardcoded to 'monitoring'. Only use if you have reviewed all manifests.
kubectl create namespace monitoring
if [ -z "${NAMESPACE}" ]; then
NAMESPACE=monitoring
fi
kubectl create namespace "$NAMESPACE"
kctl() {
kubectl --namespace "$NAMESPACE" "$@"
}
kctl apply -f manifests/prometheus-operator
kubectl apply -f ${manifest_prefix}/manifests/prometheus-operator/
# Wait for CRDs to be ready.
printf "Waiting for Operator to register custom resource definitions..."
until kctl get customresourcedefinitions servicemonitors.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kctl get customresourcedefinitions prometheuses.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kctl get customresourcedefinitions alertmanagers.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kctl get servicemonitors.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kctl get prometheuses.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kctl get alertmanagers.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kubectl get customresourcedefinitions servicemonitors.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kubectl get customresourcedefinitions prometheuses.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kubectl get customresourcedefinitions alertmanagers.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kubectl get servicemonitors.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kubectl get prometheuses.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
until kubectl get alertmanagers.monitoring.coreos.com > /dev/null 2>&1; do sleep 1; printf "."; done
echo "done!"
kctl apply -f manifests/node-exporter
kctl apply -f manifests/kube-state-metrics
kctl apply -f manifests/grafana/grafana-credentials.yaml
kctl apply -f manifests/grafana
find manifests/prometheus -type f ! -name prometheus-k8s-roles.yaml ! -name prometheus-k8s-role-bindings.yaml -exec kubectl --namespace "$NAMESPACE" apply -f {} \;
kubectl apply -f manifests/prometheus/prometheus-k8s-roles.yaml
kubectl apply -f manifests/prometheus/prometheus-k8s-role-bindings.yaml
kctl apply -f manifests/alertmanager/
kubectl apply -f ${manifest_prefix}/manifests/node-exporter/
kubectl apply -f ${manifest_prefix}/manifests/kube-state-metrics/
kubectl apply -f ${manifest_prefix}/manifests/grafana/
kubectl apply -f ${manifest_prefix}/manifests/prometheus-k8s/
kubectl apply -f ${manifest_prefix}/manifests/alertmanager-main/

View File

@@ -1,17 +0,0 @@
#!/usr/bin/env bash
# We assume that the kubelet uses token authN and authZ, as otherwise
# Prometheus needs a client certificate, which gives it full access to the
# kubelet, rather than just the metrics. Token authN and authZ allows more fine
# grained and easier access control. Simply start minikube with the following
# command (you can of course adapt the version and memory to your needs):
#
# $ minikube delete && minikube start --kubernetes-version=v1.9.1 --memory=4096 --bootstrapper=kubeadm --extra-config=kubelet.authentication-token-webhook=true --extra-config=kubelet.authorization-mode=Webhook --extra-config=scheduler.address=0.0.0.0 --extra-config=controller-manager.address=0.0.0.0
#
# In future versions of minikube and kubeadm this will be the default, but for
# the time being, we will have to configure it ourselves.
hack/cluster-monitoring/deploy
kubectl --namespace=kube-system apply -f manifests/k8s/kubeadm/

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
hack/cluster-monitoring/teardown
kubectl --namespace=kube-system delete -f manifests/k8s/minikube

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
hack/cluster-monitoring/deploy
kubectl apply -f manifests/k8s/self-hosted

View File

@@ -1,6 +0,0 @@
#!/usr/bin/env bash
hack/cluster-monitoring/teardown
kubectl delete -f manifests/k8s/self-hosted

View File

@@ -1,30 +1,4 @@
#!/usr/bin/env bash
if [ -z "${KUBECONFIG}" ]; then
export KUBECONFIG=~/.kube/config
fi
# CAUTION - NAMESPACE must match its value when deploy script was run.
# Some resources are always deployed to the monitoring namespace.
if [ -z "${NAMESPACE}" ]; then
NAMESPACE=monitoring
fi
kctl() {
kubectl --namespace "$NAMESPACE" "$@"
}
kctl delete -f manifests/node-exporter
kctl delete -f manifests/kube-state-metrics
kctl delete -f manifests/grafana
find manifests/prometheus -type f ! -name prometheus-k8s-roles.yaml ! -name prometheus-k8s-role-bindings.yaml -exec kubectl --namespace "$NAMESPACE" delete -f {} \;
kubectl delete -f manifests/prometheus/prometheus-k8s-roles.yaml
kubectl delete -f manifests/prometheus/prometheus-k8s-role-bindings.yaml
kctl delete -f manifests/alertmanager
# Hack: wait a bit to let the controller delete the deployed Prometheus server.
sleep 5
kctl delete -f manifests/prometheus-operator
kubectl delete namespace monitoring

View File

@@ -1,3 +1,3 @@
#!/usr/bin/env bash
kubectl apply -f manifests/examples/example-app
kubectl apply -f examples/example-app

View File

@@ -1,3 +1,3 @@
#!/usr/bin/env bash
kubectl delete -f manifests/examples/example-app
kubectl delete -f examples/example-app

25
hack/scripts/build-jsonnet.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e
set -x
jsonnet="${1-kube-prometheus.jsonnet}"
prefix="${2-manifests}"
json="tmp/manifests.json"
rm -rf ${prefix}
mkdir -p $(dirname "${json}")
jsonnet \
-J $GOPATH/src/github.com/ksonnet/ksonnet-lib \
-J $GOPATH/src/github.com/grafana/grafonnet-lib \
-J $GOPATH/src/github.com/coreos/prometheus-operator/contrib/kube-prometheus/jsonnet \
-J $GOPATH/src/github.com/brancz/kubernetes-grafana/src/kubernetes-jsonnet \
${jsonnet} > ${json}
files=$(jq -r 'keys[]' ${json})
for file in ${files}; do
dir=$(dirname "${file}")
path="${prefix}/${dir}"
mkdir -p ${path}
jq -r ".[\"${file}\"]" ${json} | gojsontoyaml -yamltojson | gojsontoyaml > "${prefix}/${file}"
done

View File

@@ -1,11 +0,0 @@
#!/bin/bash
cat <<-EOF
apiVersion: v1
kind: Secret
metadata:
name: alertmanager-main
data:
alertmanager.yaml: $(cat assets/alertmanager/alertmanager.yaml | base64 --wrap=0)
EOF

View File

@@ -1,39 +0,0 @@
#!/bin/bash
set -e
set +x
cat <<-EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-dashboard-definitions-0
data:
EOF
for f in assets/grafana/generated/*-dashboard.json
do
rm -rf $f
done
virtualenv -p python3 .env 2>&1 > /dev/null
source .env/bin/activate 2>&1 > /dev/null
pip install -Ur requirements.txt 2>&1 > /dev/null
for f in assets/grafana/*.dashboard.py
do
basefilename=$(basename $f)
JSON_FILENAME="assets/grafana/generated/${basefilename%%.*}-dashboard.json"
generate-dashboard $f -o $JSON_FILENAME 2>&1 > /dev/null
done
cp assets/grafana/raw-json-dashboards/*-dashboard.json assets/grafana/generated/
for f in assets/grafana/generated/*-dashboard.json
do
basefilename=$(basename $f)
echo " $basefilename: |+"
if [ "$basefilename" = "etcd-dashboard.json" ]; then
hack/scripts/wrap-dashboard.sh $f prometheus-etcd | sed "s/^/ /g"
else
hack/scripts/wrap-dashboard.sh $f prometheus | sed "s/^/ /g"
fi
done

View File

@@ -1,20 +0,0 @@
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 user password"
exit 1
fi
user=$1
password=$2
cat <<-EOF
apiVersion: v1
kind: Secret
metadata:
name: grafana-credentials
data:
user: $(echo -n ${user} | base64 --wrap=0)
password: $(echo -n ${password} | base64 --wrap=0)
EOF

View File

@@ -1,26 +0,0 @@
#!/bin/bash
set -e
set +x
# Generate Alert Rules ConfigMap
hack/scripts/generate-rules-configmap.sh > manifests/prometheus/prometheus-k8s-rules.yaml
# Generate Dashboard ConfigMap
hack/scripts/generate-dashboards-configmap.sh > manifests/grafana/grafana-dashboard-definitions.yaml
# Generate Dashboard ConfigMap with configmap-generator tool
# Max Size per ConfigMap: 240000
# Input dir: assets/grafana
# output file: manifests/grafana/grafana-dashboards.yaml
# grafana deployment output file: manifests/grafana/grafana-deployment.yaml
test -f manifests/grafana/grafana-dashboard-definitions.yaml && rm -f manifests/grafana/grafana-dashboard-definitions.yaml
test -f manifests/grafana/grafana-deployment.yaml && rm -f manifests/grafana/grafana-deployment.yaml
test -f manifests/grafana/grafana-dashboards.yaml && rm -f manifests/grafana/grafana-dashboards.yaml
hack/grafana-dashboards-configmap-generator/bin/grafana_dashboards_generate.sh -s 240000 -i assets/grafana/generated -o manifests/grafana/grafana-dashboard-definitions.yaml -g manifests/grafana/grafana-deployment.yaml -d manifests/grafana/grafana-dashboards.yaml
# Generate Grafana Credentials Secret
hack/scripts/generate-grafana-credentials-secret.sh admin admin > manifests/grafana/grafana-credentials.yaml
# Generate Secret for Alertmanager config
hack/scripts/generate-alertmanager-config-secret.sh > manifests/alertmanager/alertmanager-config.yaml

View File

@@ -1,18 +0,0 @@
#!/bin/bash
cat <<-EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-k8s-rules
labels:
role: alert-rules
prometheus: k8s
data:
EOF
for f in assets/prometheus/rules/*.rules.y*ml
do
echo " $(basename "$f"): |+"
cat $f | sed "s/^/ /g"
done

View File

@@ -1,51 +0,0 @@
#!/bin/bash -eu
# Intended usage:
# * Edit dashboard in Grafana (you need to login first with admin/admin
# login/password).
# * Save dashboard in Grafana to check is specification is correct.
# Looks like this is the only way to check if dashboard specification
# has errors.
# * Download dashboard specification as JSON file in Grafana:
# Share -> Export -> Save to file.
# * Drop dashboard specification in assets folder:
# mv Nodes-1488465802729.json assets/grafana/node-dashboard.json
# * Regenerate Grafana configmap:
# ./hack/scripts/generate-manifests.sh
# * Apply new configmap:
# kubectl -n monitoring apply -f manifests/grafana/grafana-cm.yaml
if [ "$#" -ne 2 ]; then
echo "Usage: $0 path-to-dashboard.json grafana-prometheus-datasource-name"
exit 1
fi
dashboardjson=$1
datasource_name=$2
inputname="DS_PROMETHEUS"
if [ "$datasource_name" = "prometheus-etcd" ]; then
inputname="DS_PROMETHEUS-ETCD"
fi
cat <<EOF
{
"dashboard":
EOF
cat $dashboardjson
cat <<EOF
,
"inputs": [
{
"name": "$inputname",
"pluginId": "prometheus",
"type": "datasource",
"value": "$datasource_name"
}
],
"overwrite": true
}
EOF