From 8a8bb283d1ab4b750e7775c1a882db1b21b2133a Mon Sep 17 00:00:00 2001 From: Chi-En Wu Date: Thu, 23 Apr 2020 14:43:48 +0800 Subject: [PATCH] docs: add description about `common.serviceMonitor` --- README.md | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/README.md b/README.md index 5dbc003..b4dbf33 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ It provides utilities that reflect best practices of Kubernetes chart developmen * [`common.secret`](#commonsecret) * [`common.service`](#commonservice) * [`common.serviceAccount`](#commonserviceaccount) + * [`common.serviceMonitor`](#commonservicemonitor) - [Partial Objects](#partial-objects) * [`common.container`](#commoncontainer) * [`common.pod.template`](#commonpodtemplate) @@ -602,6 +603,89 @@ metadata: +### `common.serviceMonitor` + +The `common.serviceMonitor` template accepts a list of three values: + +- `$top`, the top context +- `$serviceMonitor`, a dictionary of values used in the service account template +- [optional] the template name of the overrides + +It creates a basic `ServiceMonitor` resource with the following defaults: + +- Namespace selector is set to the release namespace +- Selector is set to + ```yaml + app.kubernetes.io/name: {{ include "common.name" }} + app.kubernetes.io/instance: {{ .Release.Name }} + ``` + to match the default used in the `Service` resource + +An example values file that can be used to configure the `ServiceMonitor` resource is: + +```yaml +serviceMonitor: + enabled: true + namespace: monitoring + port: 80 + path: /path/to/metrics + interval: 30s + scrapeTimeout: 30s + basicAuth: + enabled: true + username: administrator + password: password +``` + +Example use: + +```yaml +{{- include "common.serviceMonitor" (list . .Values.serviceMonitor) -}} + +## The following is the same as above: +# {{- include "common.serviceMonitor" (list . .Values.serviceMonitor "mychart.serviceMonitor") -}} +# {{- define "mychart.serviceMonitor" -}} +# {{- end -}} +``` + +Output: + +```yaml +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/instance: release-name + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: mychart + app.kubernetes.io/version: 1.16.0 + helm.sh/chart: mychart-0.1.0 + name: release-name-mychart + namespace: monitoring +spec: + endpoints: + - basicAuth: + password: + key: password + name: release-name-mychart + username: + key: username + name: release-name-mychart + interval: 30s + path: /path/to/metrics + port: 80 + scrapeTimeout: 30s + namespaceSelector: + matchNames: + - default + selector: + matchLabels: + app.kubernetes.io/instance: release-name + app.kubernetes.io/name: mychart +``` + + + ## Partial Objects When writing Kubernetes resources, you may find the following helpers useful to construct parts of the spec.