prometheus-cr
by somaz94
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
| Resource | API | Created from |
|---|---|---|
ServiceMonitor | monitoring.coreos.com/v1 | serviceMonitors[] |
PodMonitor | monitoring.coreos.com/v1 | podMonitors[] |
PrometheusRule | monitoring.coreos.com/v1 | prometheusRules[] |
Probe | monitoring.coreos.com/v1 | probes[] |
ScrapeConfig | monitoring.coreos.com/v1alpha1 | scrapeConfigs[] |
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
ServiceMonitoris not enough on its own — the Prometheus CR'sserviceMonitorSelector/ruleSelector/probeSelector/scrapeConfigSelector(and matching*NamespaceSelector) must match. Either add the label the selector expects tocommonLabels, or set the relevant*SelectorNilUsesHelmValues: falsein 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
| Key | Type | Default | Description |
|---|---|---|---|
commonLabels | map | {} | Labels added to every resource. Add the label your Prometheus selector expects here. |
commonAnnotations | map | {} | Annotations added to every resource. |
serviceMonitors[]
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | ServiceMonitor name. |
namespace | string | no | Target namespace (default: release namespace). |
selector | map | no | Service label selector (defaults to match-all). |
namespaceSelector | map | no | { any: true } or { matchNames: [...] }. |
endpoints | list | no | Endpoint scrape configs (port, path, interval, scheme, tlsConfig, relabelings, ...). |
jobLabel | string | no | Service label to use as the job label. |
targetLabels / podTargetLabels | list | no | Labels to copy onto scraped metrics. |
sampleLimit | integer | no | Per-scrape sample limit. |
labels / annotations / specExtra | map | no | Extra metadata / escape hatch. |
podMonitors[]
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | PodMonitor name. |
namespace | string | no | Target namespace (default: release namespace). |
selector | map | no | Pod label selector (defaults to match-all). |
namespaceSelector | map | no | { any: true } or { matchNames: [...] }. |
podMetricsEndpoints | list | no | Pod endpoint scrape configs. |
jobLabel | string | no | Pod label to use as the job label. |
podTargetLabels | list | no | Pod labels to copy onto scraped metrics. |
sampleLimit | integer | no | Per-scrape sample limit. |
labels / annotations / specExtra | map | no | Extra metadata / escape hatch. |
prometheusRules[]
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | PrometheusRule name. |
namespace | string | no | Target namespace (default: release namespace). |
groups | list | yes | Rule groups: { name, interval?, rules[] }; each rule is { alert|record, expr, for?, labels?, annotations? }. |
labels / annotations / specExtra | map | no | Extra metadata / escape hatch. |
probes[]
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | Probe name. |
namespace | string | no | Target namespace (default: release namespace). |
jobName | string | no | Value of the job label. |
prober | map | no | { url, scheme, path, proxyUrl } of the prober (blackbox-exporter). |
module | string | no | Prober module (e.g. http_2xx). |
targets | map | no | { staticConfig: {...} } or { ingress: {...} }. |
interval / scrapeTimeout | string | no | Scrape timing. |
labels / annotations / specExtra | map | no | Extra metadata / escape hatch. |
scrapeConfigs[]
| Key | Type | Required | Description |
|---|---|---|---|
name | string | yes | ScrapeConfig name. |
namespace | string | no | Target namespace (default: release namespace). |
jobName | string | no | Value of the job label. |
staticConfigs | list | no | { targets: [...], labels: {...} }. |
scrapeInterval / scrapeTimeout | string | no | Scrape timing. |
metricsPath | string | no | Metrics path (default /metrics). |
scheme | string | no | HTTP | HTTPS. |
relabelings / metricRelabelings | list | no | Relabel configs. |
labels / annotations | map | no | Extra metadata. |
specExtra | map | no | Escape 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartprometheus-cr is pinned at v0.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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