Skip to content

Commit

Permalink
chore(kube-monitoring): Add limitation to pod sd target selection (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtief authored Feb 5, 2025
1 parent 4601a33 commit 3bfccae
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
9 changes: 8 additions & 1 deletion kube-monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ Greenhouse regularly performs integration tests that are bundled with **kube-mon

## 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 annotation `greenhouse/scrape: “true”`.
The **kube-monitoring** Plugin provides 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 if the following annotations are set:

```yaml
metadata:
annotations:
greenhouse/scrape: “true”
greenhouse/target: <kube-monitoring plugin name>
```
*Note:* The annotations needs to be added manually to have the pod scraped and the port name needs to match.
Expand Down
2 changes: 1 addition & 1 deletion kube-monitoring/charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ maintainers:
name: kube-monitoring
sources:
- https://github.com/cloudoperators/greenhouse-extensions
version: 0.21.1
version: 0.21.2
# prometheus-operator app version
appVersion: v0.77.1
keywords:
Expand Down
10 changes: 9 additions & 1 deletion kube-monitoring/charts/templates/podmonitor-sd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ spec:
sourceLabels:
- __meta_kubernetes_pod_annotation_greenhouse_scrape
regex: "true"
{{- if $values.limitToPrometheusTargets }}
- action: keep
sourceLabels:
- __meta_kubernetes_pod_annotation_greenhouse_target
regex: {{ $.Release.Name | quote }}
{{- end }}
- action: labelmap
regex: '__meta_kubernetes_pod_label_(.+)'
- sourceLabels:
Expand All @@ -36,7 +42,9 @@ spec:
namespaceSelector:
{{ toYaml $values.namespaceSelector | indent 4 }}
selector:
{{ tpl (toYaml $values.selector) . | indent 4 }}
matchExpressions:
- key: do-not-select
operator: DoesNotExist
{{- if $values.podTargetLabels }}
podTargetLabels:
{{ toYaml $values.podTargetLabels | indent 4 }}
Expand Down
12 changes: 3 additions & 9 deletions kube-monitoring/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ kubeMonitoring:
pods:
enabled: true

## To avoid multiple pod scrapes from different Prometheis, service discovery can be limited to one target
limitToPrometheusTargets: true

## Monitor Pods with the following port name
port: metrics

Expand Down Expand Up @@ -244,15 +247,6 @@ kubeMonitoring:
##
# matchNames: []

## Custom definition to pick up specific pods with an expression.
selector:
matchExpressions: []

## label selector for pods
##
matchLabels:
plugin: "{{ $.Release.Name }}"

## SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
##
# sampleLimit: 0
Expand Down
4 changes: 2 additions & 2 deletions kube-monitoring/plugindefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ kind: PluginDefinition
metadata:
name: kube-monitoring
spec:
version: 2.8.1
version: 2.8.2
displayName: Kubernetes monitoring
description: Native deployment and management of Prometheus along with Kubernetes cluster monitoring components.
docMarkDownUrl: https://raw.githubusercontent.com/cloudoperators/greenhouse-extensions/main/kube-monitoring/README.md
icon: https://raw.githubusercontent.com/cloudoperators/greenhouse-extensions/main/kube-monitoring/logo.png
helmChart:
name: kube-monitoring
repository: oci://ghcr.io/cloudoperators/greenhouse-extensions/charts
version: 0.21.1
version: 0.21.2
options:
- name: global.commonLabels
description: Labels to add to all resources. This can be used to add a support group or service to all alerts.
Expand Down

0 comments on commit 3bfccae

Please sign in to comment.