Skip to content

Commit 86c9205

Browse files
richardtiefviennaa
andauthored
feat(kube-monitoring): Add Pod service discovery (#553)
* feat(kube-monitoring): Add Pod service discovery * chore(kube-monitoring): adapt charts tests for pods sd * docs(kube-monitoring): add important note to Pod SD Co-authored-by: Tommy Sauer <tommy.sauer@sap.com> * chore(kube-monitoring): more precise selector description Co-authored-by: Tommy Sauer <tommy.sauer@sap.com> --------- Co-authored-by: Tommy Sauer <tommy.sauer@sap.com>
1 parent 5fa57cd commit 86c9205

File tree

7 files changed

+105
-20
lines changed

7 files changed

+105
-20
lines changed

kube-monitoring/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ Greenhouse regularly performs integration tests that are bundled with **kube-mon
124124
| `alerts.alertmanager.tlsConfig.cert` | TLS certificate for communication with Alertmanager | `Secret` |
125125
| `alerts.alertmanager.tlsConfig.key` | TLS key for communication with Alertmanager | `Secret` |
126126

127+
## Service Discovery
128+
129+
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”`.
130+
131+
*Important*: The label needs to be added manually to have the pod scraped and the port name needs to match.
132+
127133
## Examples
128134

129135
### Deploy kube-monitoring into a remote cluster

kube-monitoring/charts/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ maintainers:
88
name: kube-monitoring
99
sources:
1010
- https://github.com/cloudoperators/greenhouse-extensions
11-
version: 0.19.2
11+
version: 0.20.0
1212
# prometheus-operator app version
1313
appVersion: v0.77.1
1414
keywords:

kube-monitoring/charts/templates/pmon.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{- if and .Values.kubeMonitoring.prometheus.enabled .Values.kubeMonitoring.serviceDiscovery.pods.enabled }}
2+
{{- $values := .Values.kubeMonitoring.serviceDiscovery.pods }}
3+
apiVersion: monitoring.coreos.com/v1
4+
kind: PodMonitor
5+
metadata:
6+
name: {{ $.Release.Name }}-pod-sd
7+
labels:
8+
{{- include "kube-prometheus-stack.labels" . | nindent 4 }}
9+
spec:
10+
{{- include "servicemonitor.scrapeLimits" . | nindent 2 }}
11+
podMetricsEndpoints:
12+
{{ tpl (toYaml $values.podMetricsEndpoints) . | indent 4 }}
13+
{{- if $values.jobLabel }}
14+
jobLabel: {{ $values.pods.jobLabel }}
15+
{{- end }}
16+
namespaceSelector:
17+
{{ toYaml $values.namespaceSelector | indent 4 }}
18+
selector:
19+
{{ toYaml $values.selector | indent 4 }}
20+
{{- if $values.podTargetLabels }}
21+
podTargetLabels:
22+
{{ toYaml $values.podTargetLabels | indent 4 }}
23+
{{- end }}
24+
{{- if $values.sampleLimit }}
25+
sampleLimit: {{ $values.sampleLimit }}
26+
{{- end }}
27+
{{- end }}

kube-monitoring/charts/templates/tests/test-kube-monitoring-config.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ data:
5454
verify "there is 1 statefulset named 'prometheus-{{ .Release.Name }}'"
5555
}
5656
57-
@test "Verify creation of the {{ .Release.Name }}-sd Podmonitor" {
58-
verify "there is 1 podmonitor named '{{ .Release.Name }}-sd'"
57+
58+
{{- if and .Values.kubeMonitoring.prometheus.enabled .Values.kubeMonitoring.serviceDiscovery.pods.enabled }}
59+
@test "Verify creation of the {{ .Release.Name }}-pod-sd Podmonitor" {
60+
verify "there is 1 podmonitor named '{{ .Release.Name }}-pod-sd'"
5961
}
62+
{{- end }}
6063
6164
@test "Verify creation of required custom resource definitions (CRDs) for {{ .Release.Name }}" {
6265
verify "there is 1 customresourcedefinition named 'prometheuses'"

kube-monitoring/charts/values.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,70 @@ kubeMonitoring:
197197
- services=[*]
198198
- statefulsets=[*]
199199

200+
## Service discovery configuration
201+
##
202+
serviceDiscovery:
203+
204+
## Configuration for the Prometheus Operator to discover pods
205+
##
206+
pods:
207+
enabled: true
208+
209+
## Endpoints of the selected pods to be monitored
210+
## https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#podmetricsendpoint
211+
##
212+
podMetricsEndpoints:
213+
## Monitor Pods with the following port name
214+
- port: metrics
215+
216+
## RelabelConfigs to apply to samples before scraping
217+
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
218+
##
219+
relabelings: []
220+
# - sourceLabels: [__meta_kubernetes_pod_node_name]
221+
# separator: ;
222+
# regex: ^(.*)$
223+
# targetLabel: nodename
224+
# replacement: $1
225+
# action: replace
226+
227+
## MetricRelabelConfigs to apply to samples after scraping, but before ingestion.
228+
## ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#relabelconfig
229+
##
230+
metricRelabelings: []
231+
# - action: keep
232+
# regex: 'kube_(daemonset|deployment|pod|namespace|node|statefulset).+'
233+
# sourceLabels: [__name__]
234+
235+
## Pod label for use in assembling a job name of the form <label value>-<port>
236+
## If no label is specified, the pod endpoint name is used.
237+
##
238+
jobLabel: ""
239+
240+
## Namespaces from which pods are selected
241+
##
242+
namespaceSelector:
243+
## Match any namespace
244+
##
245+
any: true
246+
247+
## Explicit list of namespace names to select
248+
##
249+
# matchNames: []
250+
251+
## Custom definition to pick up specific pods with an expression.
252+
selector:
253+
matchExpressions: []
254+
255+
## label selector for pods
256+
##
257+
matchLabels:
258+
greenhouse/scrape: "true"
259+
260+
## SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
261+
##
262+
# sampleLimit: 0
263+
200264
## Configuration for the Prometheus instance
201265
##
202266
prometheus:

kube-monitoring/plugindefinition.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ kind: PluginDefinition
66
metadata:
77
name: kube-monitoring
88
spec:
9-
version: 2.6.5
9+
version: 2.7.0
1010
displayName: Kubernetes monitoring
1111
description: Native deployment and management of Prometheus along with Kubernetes cluster monitoring components.
1212
docMarkDownUrl: https://raw.githubusercontent.com/cloudoperators/greenhouse-extensions/main/kube-monitoring/README.md
1313
icon: https://raw.githubusercontent.com/cloudoperators/greenhouse-extensions/main/kube-monitoring/logo.png
1414
helmChart:
1515
name: kube-monitoring
1616
repository: oci://ghcr.io/cloudoperators/greenhouse-extensions/charts
17-
version: 0.19.2
17+
version: 0.20.0
1818
options:
1919
- name: global.commonLabels
2020
description: Labels to add to all resources. This can be used to add a support group or service to all alerts.

0 commit comments

Comments
 (0)