From b3ab55560369c503834604090388ace7c65c0c80 Mon Sep 17 00:00:00 2001
From: Joshua Olson <joshua.olson.490@gmail.com>
Date: Wed, 1 Aug 2018 07:58:40 -0500
Subject: [PATCH] kube-prometheus: expand the minikube.jsonnet example

---
 README.md                 | 23 +---------------------
 examples/minikube.jsonnet | 41 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/README.md b/README.md
index 6dac4bd3..53c230f0 100644
--- a/README.md
+++ b/README.md
@@ -383,31 +383,10 @@ See [exposing Prometheus/Alertmanager/Grafana](docs/exposing-prometheus-alertman
 
 ## Minikube Example
 
-To use an easy to reproduce example, let's take the minikube setup as demonstrated in [Prerequisites](#prerequisites). It is a kubeadm cluster (as we use the kubeadm bootstrapper) and because we would like easy access to our Prometheus, Alertmanager and Grafana UI we want the services to be exposed as NodePort type services:
+To use an easy to reproduce example, see [minikube.jsonnet](examples/minikube.jsonnet), which uses the minikube setup as demonstrated in [Prerequisites](#prerequisites). Because we would like easy access to our Prometheus, Alertmanager and Grafana UIs, `minikube.jsonnet` exposes the services as NodePort type services.
 
 > Note that NodePort type services is likely not a good idea for your production use case, it is only used for demonstration purposes here.
 
-[embedmd]:# (examples/minikube.jsonnet)
-```jsonnet
-local kp =
-  (import 'kube-prometheus/kube-prometheus.libsonnet') +
-  (import 'kube-prometheus/kube-prometheus-kubeadm.libsonnet') +
-  (import 'kube-prometheus/kube-prometheus-node-ports.libsonnet') +
-  {
-    _config+:: {
-      namespace: 'monitoring',
-    },
-  };
-
-{ ['00namespace-' + name]: kp.kubePrometheus[name] for name in std.objectFields(kp.kubePrometheus) } +
-{ ['0prometheus-operator-' + name]: kp.prometheusOperator[name] for name in std.objectFields(kp.prometheusOperator) } +
-{ ['node-exporter-' + name]: kp.nodeExporter[name] for name in std.objectFields(kp.nodeExporter) } +
-{ ['kube-state-metrics-' + name]: kp.kubeStateMetrics[name] for name in std.objectFields(kp.kubeStateMetrics) } +
-{ ['alertmanager-' + name]: kp.alertmanager[name] for name in std.objectFields(kp.alertmanager) } +
-{ ['prometheus-' + name]: kp.prometheus[name] for name in std.objectFields(kp.prometheus) } +
-{ ['grafana-' + name]: kp.grafana[name] for name in std.objectFields(kp.grafana) }
-```
-
 ## Troubleshooting
 
 ### Error retrieving kubelet metrics
diff --git a/examples/minikube.jsonnet b/examples/minikube.jsonnet
index ed1a05c4..9eda7c4f 100644
--- a/examples/minikube.jsonnet
+++ b/examples/minikube.jsonnet
@@ -5,6 +5,47 @@ local kp =
   {
     _config+:: {
       namespace: 'monitoring',
+      alertmanager+:: {
+        config: importstr 'alertmanager-config.yaml',
+      },
+      grafana+:: {
+        config: {
+          sections: {
+            // Do not require grafana users to login/authenticate
+            "auth.anonymous": {enabled: true},
+          },
+        },
+      },
+    },
+
+    // For simplicity, each of the following values for 'externalUrl':
+    //  * assume that `minikube ip` prints "192.168.99.100"
+    //  * hard-code the NodePort for each app
+    prometheus+:: {
+      prometheus+: {
+        // Reference info: https://coreos.com/operators/prometheus/docs/latest/api.html#prometheusspec
+        spec+: {
+          // An e.g. of the purpose of this is so the "Source" links on http://<alert-manager>/#/alerts are valid.
+          externalUrl: "http://192.168.99.100:30900",
+
+          // Reference info: "external_labels" on https://prometheus.io/docs/prometheus/latest/configuration/configuration/
+          externalLabels: {
+            // This 'cluster' label will be included on every firing prometheus alert. (This is more useful
+            // when running multiple clusters in a shared environment (e.g. AWS) with other users.)
+            cluster: "minikube-<INSERT YOUR USERNAME HERE>",
+          },
+        },
+      },
+    },
+    alertmanager+:: {
+      alertmanager+: {
+        // Reference info: https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#alertmanagerspec
+        spec+: {
+          externalUrl: "http://192.168.99.100:30903",
+
+          logLevel: "debug", // So firing alerts show up in log
+        },
+      },
     },
   };
 
-- 
GitLab