Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kube-monitoring): Add Pod service discovery #553

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kube-monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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”`.
richardtief marked this conversation as resolved.
Show resolved Hide resolved

## Examples

### Deploy kube-monitoring into a remote cluster
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.19.2
version: 0.20.0
# prometheus-operator app version
appVersion: v0.77.1
keywords:
Expand Down
15 changes: 0 additions & 15 deletions kube-monitoring/charts/templates/pmon.yaml

This file was deleted.

27 changes: 27 additions & 0 deletions kube-monitoring/charts/templates/podmonitor-sd.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
65 changes: 65 additions & 0 deletions kube-monitoring/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <label value>-<port>
## If no label is specified, the pod endpoint name is used.
##
jobLabel: ""

## Namespaces from which pods are selected
##
namespaceSelector:
## Match any namespace
##
any: true

## Explicit list of namespace names to select
##
# matchNames: []

## Example which selects all Pods to be monitored
## with label "monitoredby" with values any of "example-pod-1" or "example-pod-2"
selector:
matchExpressions: []
richardtief marked this conversation as resolved.
Show resolved Hide resolved

## label selector for pods
##
matchLabels:
greenhouse/scrape: "true"
viennaa marked this conversation as resolved.
Show resolved Hide resolved

## SampleLimit defines per-scrape limit on number of scraped samples that will be accepted.
##
# sampleLimit: 0

## Configuration for the Prometheus instance
##
prometheus:
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.6.5
version: 2.7.0
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.19.2
version: 0.20.0
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
Loading