Skip to content

Commit 7b0d932

Browse files
committed
Add README.md from the kubernetes-mixin.
Signed-off-by: Tom Wilkie <[email protected]>
1 parent dfd2691 commit 7b0d932

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

README.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Prometheus Monitoring Mixin for Kubernetes
2+
3+
> NOTE: This project is *alpha* stage. Flags, configuration, behaviour and design may change significantly in following releases.
4+
5+
A set of Grafana dashboards and Prometheus alerts for Kubernetes.
6+
7+
## How to use
8+
9+
This mixin is designed to be vendored into the repo with your infrastructure config.
10+
To do this, use [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler):
11+
12+
You then have three options for deploying your dashboards
13+
1. Generate the config files and deploy them yourself
14+
1. Use ksonnet to deploy this mixin along with Prometheus and Grafana
15+
1. Use prometheus-operator to deploy this mixin (TODO)
16+
17+
## Generate config files
18+
19+
You can manually generate the alerts, dashboards and rules files, but first you
20+
must install some tools:
21+
22+
```
23+
$ go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
24+
$ brew install jsonnet
25+
```
26+
27+
Then, grab the mixin and its dependencies:
28+
29+
```
30+
$ git clone https://github.com/kubernetes-monitoring/kubernetes-mixin
31+
$ cd kubernetes-mixin
32+
$ jb install
33+
```
34+
35+
Finally, build the mixin:
36+
37+
```
38+
$ make prometheus_alerts.yaml
39+
$ make prometheus_rules.yaml
40+
$ make dashboards_out
41+
```
42+
43+
The `prometheus_alerts.yaml` and `prometheus_rules.yaml` file then need to passed
44+
to your Prometheus server, and the files in `dashboards_out` need to be imported
45+
into you Grafana server. The exact details will depending on how you deploy your
46+
monitoring stack to Kubernetes.
47+
48+
## Using with prometheus-ksonnet
49+
50+
Alternatively you can also use the mixin with
51+
[prometheus-ksonnet](https://github.com/kausalco/public/tree/master/prometheus-ksonnet),
52+
a [ksonnet](https://github.com/ksonnet/ksonnet) module to deploy a fully-fledged
53+
Prometheus-based monitoring system for Kubernetes:
54+
55+
Make sure you have the ksonnet v0.8.0:
56+
57+
```
58+
$ brew install https://raw.githubusercontent.com/ksonnet/homebrew-tap/82ef24cb7b454d1857db40e38671426c18cd8820/ks.rb
59+
$ brew pin ks
60+
$ ks version
61+
ksonnet version: v0.8.0
62+
jsonnet version: v0.9.5
63+
client-go version: v1.6.8-beta.0+$Format:%h$
64+
```
65+
66+
In your config repo, if you don't have a ksonnet application, make a new one (will copy credentials from current context):
67+
68+
```
69+
$ ks init <application name>
70+
$ cd <application name>
71+
$ ks env add default
72+
```
73+
74+
Grab the kubernetes-jsonnet module using and its dependencies, which include
75+
the kubernetes-mixin:
76+
77+
```
78+
$ go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
79+
$ jb init
80+
$ jb install github.com/kausalco/public/prometheus-ksonnet
81+
82+
```
83+
84+
Assuming you want to run in the default namespace ('environment' in ksonnet parlance), add the follow to the file `environments/default/main.jsonnet`:
85+
86+
```
87+
local prometheus = import "prometheus-ksonnet/prometheus-ksonnet.libsonnet";
88+
89+
prometheus {
90+
_config+:: {
91+
namespace: "default",
92+
},
93+
}
94+
```
95+
96+
Apply your config:
97+
98+
```
99+
$ ks apply default
100+
```
101+
102+
## Using prometheus-operator
103+
104+
TODO
105+
106+
## Customising the mixin
107+
108+
Kubernetes-mixin allows you to override the selectors used for various jobs,
109+
to match those used in your Prometheus set.
110+
111+
In a new directory, add a file `mixin.libsonnet`:
112+
113+
```
114+
local kubernetes = import "kubernetes-mixin/mixin.libsonnet";
115+
116+
kubernetes {
117+
_config+:: {
118+
kubeStateMetricsSelector: 'job="kube-state-metrics"',
119+
cadvisorSelector: 'job="kubernetes-cadvisor"',
120+
nodeExporterSelector: 'job="kubernetes-node-exporter"',
121+
kubeletSelector: 'job="kubernetes-kubelet"',
122+
},
123+
}
124+
```
125+
126+
Then, install the kubernetes-mixin:
127+
128+
```
129+
$ jb init
130+
$ jb install github.com/kubernetes-monitoring/kubernetes-mixin
131+
```
132+
133+
Generate the alerts, rules and dashboards:
134+
135+
```
136+
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusAlerts)' > alerts.yml
137+
$ jsonnet -J vendor -S -e 'std.manifestYamlDoc((import "mixin.libsonnet").prometheusRules)' >files/rules.yml
138+
$ jsonnet -J vendor -m files/dashboards -e '(import "mixin.libsonnet").grafanaDashboards'
139+
```
140+
141+
## Background
142+
143+
* For more motivation, see
144+
"[The RED Method: How to instrument your services](https://kccncna17.sched.com/event/CU8K/the-red-method-how-to-instrument-your-services-b-tom-wilkie-kausal?iframe=no&w=100%&sidebar=yes&bg=no)" talk from CloudNativeCon Austin.
145+
* For more information about monitoring mixins, see this [design doc](https://docs.google.com/document/d/1A9xvzwqnFVSOZ5fD3blKODXfsat5fg6ZhnKu9LK3lB4/edit#).

0 commit comments

Comments
 (0)