From 84b8507fe452fe24b1f0baeb7aefdeb60e60e76f Mon Sep 17 00:00:00 2001 From: Richard Tief Date: Thu, 12 Dec 2024 14:51:10 +0100 Subject: [PATCH 1/4] feat(kube-monitoring): Add Pod service discovery --- kube-monitoring/README.md | 4 ++ kube-monitoring/charts/Chart.yaml | 2 +- kube-monitoring/charts/templates/pmon.yaml | 15 ----- .../charts/templates/podmonitor-sd.yaml | 27 ++++++++ kube-monitoring/charts/values.yaml | 65 +++++++++++++++++++ kube-monitoring/plugindefinition.yaml | 4 +- 6 files changed, 99 insertions(+), 18 deletions(-) delete mode 100644 kube-monitoring/charts/templates/pmon.yaml create mode 100644 kube-monitoring/charts/templates/podmonitor-sd.yaml diff --git a/kube-monitoring/README.md b/kube-monitoring/README.md index 4f7f7cc5..97011ba0 100644 --- a/kube-monitoring/README.md +++ b/kube-monitoring/README.md @@ -124,6 +124,10 @@ 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”`. + ## 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/values.yaml b/kube-monitoring/charts/values.yaml index 04287c50..ccd7e795 100644 --- a/kube-monitoring/charts/values.yaml +++ b/kube-monitoring/charts/values.yaml @@ -197,6 +197,71 @@ 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