prometheus-cr

by somaz94

Helm chartv0.1.0App 1.0.0Apache-2.0Verified publisher

Custom resources for the Prometheus Operator — ServiceMonitor, PodMonitor, PrometheusRule, Probe (monitoring.coreos.com/v1) and ScrapeConfig (monitoring.coreos.com/v1alpha1). Deployed alongside kube-prometheus-stack / prometheus-operator, which installs the operator and CRDs but leaves app-level monitoring CRs to each consumer.

About this chart

prometheus-cr

Data-driven Prometheus Operator monitoring custom resources, deployed as a Helm release alongside kube-prometheus-stack / prometheus-operator.

The prometheus-operator (via kube-prometheus-stack) installs the operator and CRDs but leaves app-level monitoring CRs (ServiceMonitor, PodMonitor, PrometheusRule, ...) to each consumer — usually hand-written per component and duplicated across repos. This chart closes that gap so cross-cutting monitoring config (scraping a third-party target, a blackbox probe, a shared alert-rule set) is managed declaratively in Git as one Helm release.

What it deploys

ResourceAPICreated from
ServiceMonitormonitoring.coreos.com/v1serviceMonitors[]
PodMonitormonitoring.coreos.com/v1podMonitors[]
PrometheusRulemonitoring.coreos.com/v1prometheusRules[]
Probemonitoring.coreos.com/v1probes[]
ScrapeConfigmonitoring.coreos.com/v1alpha1scrapeConfigs[]

Every list defaults to empty, so an unconfigured helm install creates nothing.

Prerequisites

  • Kubernetes >= 1.25
  • Prometheus Operator and its CRDs already installed — typically via kube-prometheus-stack or the prometheus-operator chart. This chart only creates monitoring CRs; it does not install the operator or its CRDs.
  • A Prometheus that selects these resources. Creating a ServiceMonitor is not enough on its own — the Prometheus CR's serviceMonitorSelector / ruleSelector / probeSelector / scrapeConfigSelector (and matching *NamespaceSelector) must match. Either add the label the selector expects to commonLabels, or set the relevant *SelectorNilUsesHelmValues: false in kube-prometheus-stack.

Install

OCI registry:

helm install monitoring-config oci://ghcr.io/somaz94/charts/prometheus-cr \
  --namespace monitoring \
  -f my-values.yaml

Classic Helm repo:

helm repo add somaz94 https://charts.somaz.blog
helm install monitoring-config somaz94/prometheus-cr \
  --namespace monitoring \
  -f my-values.yaml

Quick examples

Scrape an app's Service

commonLabels:
  release: kube-prometheus-stack   # so the stack's selector picks it up

serviceMonitors:
  - name: my-app
    selector:
      matchLabels:
        app.kubernetes.io/name: my-app
    namespaceSelector:
      matchNames:
        - my-app
    endpoints:
      - port: http-metrics
        path: /metrics
        interval: 30s

A shared alert-rule set

prometheusRules:
  - name: platform-rules
    groups:
      - name: platform.rules
        rules:
          - alert: TargetDown
            expr: up == 0
            for: 5m
            labels:
              severity: critical
            annotations:
              summary: "{{ $labels.job }} target is down"

Blackbox probe of external endpoints

probes:
  - name: external-endpoints
    jobName: blackbox
    prober:
      url: blackbox-exporter.monitoring.svc:9115
    module: http_2xx
    targets:
      staticConfig:
        static:
          - https://example.com
          - https://api.example.com

Scrape static targets outside the cluster

scrapeConfigs:
  - name: external-nodes
    staticConfigs:
      - targets:
          - 192.0.2.10:9100
          - 192.0.2.11:9100
        labels:
          env: prod
    scrapeInterval: 30s

Values reference

Shared metadata

KeyTypeDefaultDescription
commonLabelsmap{}Labels added to every resource. Add the label your Prometheus selector expects here.
commonAnnotationsmap{}Annotations added to every resource.

serviceMonitors[]

KeyTypeRequiredDescription
namestringyesServiceMonitor name.
namespacestringnoTarget namespace (default: release namespace).
selectormapnoService label selector (defaults to match-all).
namespaceSelectormapno{ any: true } or { matchNames: [...] }.
endpointslistnoEndpoint scrape configs (port, path, interval, scheme, tlsConfig, relabelings, ...).
jobLabelstringnoService label to use as the job label.
targetLabels / podTargetLabelslistnoLabels to copy onto scraped metrics.
sampleLimitintegernoPer-scrape sample limit.
labels / annotations / specExtramapnoExtra metadata / escape hatch.

podMonitors[]

KeyTypeRequiredDescription
namestringyesPodMonitor name.
namespacestringnoTarget namespace (default: release namespace).
selectormapnoPod label selector (defaults to match-all).
namespaceSelectormapno{ any: true } or { matchNames: [...] }.
podMetricsEndpointslistnoPod endpoint scrape configs.
jobLabelstringnoPod label to use as the job label.
podTargetLabelslistnoPod labels to copy onto scraped metrics.
sampleLimitintegernoPer-scrape sample limit.
labels / annotations / specExtramapnoExtra metadata / escape hatch.

prometheusRules[]

KeyTypeRequiredDescription
namestringyesPrometheusRule name.
namespacestringnoTarget namespace (default: release namespace).
groupslistyesRule groups: { name, interval?, rules[] }; each rule is { alert|record, expr, for?, labels?, annotations? }.
labels / annotations / specExtramapnoExtra metadata / escape hatch.

probes[]

KeyTypeRequiredDescription
namestringyesProbe name.
namespacestringnoTarget namespace (default: release namespace).
jobNamestringnoValue of the job label.
probermapno{ url, scheme, path, proxyUrl } of the prober (blackbox-exporter).
modulestringnoProber module (e.g. http_2xx).
targetsmapno{ staticConfig: {...} } or { ingress: {...} }.
interval / scrapeTimeoutstringnoScrape timing.
labels / annotations / specExtramapnoExtra metadata / escape hatch.

scrapeConfigs[]

KeyTypeRequiredDescription
namestringyesScrapeConfig name.
namespacestringnoTarget namespace (default: release namespace).
jobNamestringnoValue of the job label.
staticConfigslistno{ targets: [...], labels: {...} }.
scrapeInterval / scrapeTimeoutstringnoScrape timing.
metricsPathstringnoMetrics path (default /metrics).
schemestringnoHTTP | HTTPS.
relabelings / metricRelabelingslistnoRelabel configs.
labels / annotationsmapnoExtra metadata.
specExtramapnoEscape hatch — use for the many *SDConfig discovery variants not surfaced.

License

Apache-2.0

Deploy prometheus-cr with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has prometheus-cr on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartprometheus-cr is pinned at v0.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply