diff --git a/kube-monitoring/README.md b/kube-monitoring/README.md index 4f7f7cc5..01b32953 100644 --- a/kube-monitoring/README.md +++ b/kube-monitoring/README.md @@ -124,6 +124,12 @@ Greenhouse regularly performs integration tests that are bundled with **kube-mon | `alerts.alertmanager.tlsConfig.cert` | TLS certificate for communication with Alertmanager | `Secret` | | `alerts.alertmanager.tlsConfig.key` | TLS key for communication with Alertmanager | `Secret` | +## Service Discovery + +The **kube-monitoring** Plugin uses a PodMonitor to automatically discover the Prometheus metrics of the Kubernetes Pods in any Namespace. The PodMonitor is configured to detect the metrics endpoint of the pods with the port name `metrics` **and** the label `greenhouse/scrape: “true”`. + +*Important*: The label needs to be added manually to have the pod scraped and the port name needs to match. + ## Examples ### Deploy kube-monitoring into a remote cluster diff --git a/kube-monitoring/charts/Chart.yaml b/kube-monitoring/charts/Chart.yaml index 4bc4a8ec..8a2e789f 100644 --- a/kube-monitoring/charts/Chart.yaml +++ b/kube-monitoring/charts/Chart.yaml @@ -8,7 +8,7 @@ maintainers: name: kube-monitoring sources: - https://github.com/cloudoperators/greenhouse-extensions -version: 0.19.2 +version: 0.20.0 # prometheus-operator app version appVersion: v0.77.1 keywords: diff --git a/kube-monitoring/charts/templates/pmon.yaml b/kube-monitoring/charts/templates/pmon.yaml deleted file mode 100644 index b201d70d..00000000 --- a/kube-monitoring/charts/templates/pmon.yaml +++ /dev/null @@ -1,15 +0,0 @@ -apiVersion: monitoring.coreos.com/v1 -kind: PodMonitor -metadata: - name: {{ $.Release.Name }}-sd - labels: - plugin: {{ $.Release.Name }} -spec: - namespaceSelector: - any: true - podMetricsEndpoints: - - port: metrics - selector: - matchExpressions: - - key: foo - operator: DoesNotExist diff --git a/kube-monitoring/charts/templates/podmonitor-sd.yaml b/kube-monitoring/charts/templates/podmonitor-sd.yaml new file mode 100644 index 00000000..7e77d13f --- /dev/null +++ b/kube-monitoring/charts/templates/podmonitor-sd.yaml @@ -0,0 +1,27 @@ +{{- if and .Values.kubeMonitoring.prometheus.enabled .Values.kubeMonitoring.serviceDiscovery.pods.enabled }} +{{- $values := .Values.kubeMonitoring.serviceDiscovery.pods }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ $.Release.Name }}-pod-sd + labels: + {{- include "kube-prometheus-stack.labels" . | nindent 4 }} +spec: + {{- include "servicemonitor.scrapeLimits" . | nindent 2 }} + podMetricsEndpoints: +{{ tpl (toYaml $values.podMetricsEndpoints) . | indent 4 }} + {{- if $values.jobLabel }} + jobLabel: {{ $values.pods.jobLabel }} + {{- end }} + namespaceSelector: +{{ toYaml $values.namespaceSelector | indent 4 }} + selector: +{{ toYaml $values.selector | indent 4 }} + {{- if $values.podTargetLabels }} + podTargetLabels: +{{ toYaml $values.podTargetLabels | indent 4 }} + {{- end }} + {{- if $values.sampleLimit }} + sampleLimit: {{ $values.sampleLimit }} + {{- end }} +{{- end }} diff --git a/kube-monitoring/charts/templates/tests/test-kube-monitoring-config.yaml b/kube-monitoring/charts/templates/tests/test-kube-monitoring-config.yaml index bc1a007c..cba05d35 100644 --- a/kube-monitoring/charts/templates/tests/test-kube-monitoring-config.yaml +++ b/kube-monitoring/charts/templates/tests/test-kube-monitoring-config.yaml @@ -54,9 +54,12 @@ data: verify "there is 1 statefulset named 'prometheus-{{ .Release.Name }}'" } - @test "Verify creation of the {{ .Release.Name }}-sd Podmonitor" { - verify "there is 1 podmonitor named '{{ .Release.Name }}-sd'" + + {{- if and .Values.kubeMonitoring.prometheus.enabled .Values.kubeMonitoring.serviceDiscovery.pods.enabled }} + @test "Verify creation of the {{ .Release.Name }}-pod-sd Podmonitor" { + verify "there is 1 podmonitor named '{{ .Release.Name }}-pod-sd'" } + {{- end }} @test "Verify creation of required custom resource definitions (CRDs) for {{ .Release.Name }}" { verify "there is 1 customresourcedefinition named 'prometheuses'" diff --git a/kube-monitoring/charts/values.yaml b/kube-monitoring/charts/values.yaml index 04287c50..5e53255c 100644 --- a/kube-monitoring/charts/values.yaml +++ b/kube-monitoring/charts/values.yaml @@ -197,6 +197,70 @@ kubeMonitoring: - services=[*] - statefulsets=[*] + ## Service discovery configuration + ## + serviceDiscovery: + + ## Configuration for the Prometheus Operator to discover pods + ## + pods: + enabled: true + + ## Endpoints of the selected pods to be monitored + ## https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#podmetricsendpoint + ## + podMetricsEndpoints: + ## Monitor Pods with the following port name + - port: metrics + + ## RelabelConfigs to apply to samples before scraping + ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig + ## + relabelings: [] + # - sourceLabels: [__meta_kubernetes_pod_node_name] + # separator: ; + # regex: ^(.*)$ + # targetLabel: nodename + # replacement: $1 + # action: replace + + ## MetricRelabelConfigs to apply to samples after scraping, but before ingestion. + ## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig + ## + metricRelabelings: [] + # - action: keep + # regex: 'kube_(daemonset|deployment|pod|namespace|node|statefulset).+' + # sourceLabels: [__name__] + + ## Pod label for use in assembling a job name of the form