Topic 55

kube-prometheus-stack

Operator

kube-prometheus-stack is the Helm chart that turned "assemble Prometheus on Kubernetes by hand" into one install: the Prometheus Operator, a Prometheus and an Alertmanager it manages, node_exporter as a DaemonSet, kube-state-metrics, and Grafana pre-loaded with dashboards and alert rules for the cluster itself. Everything Mara ran via Compose on obs-01 arrives as a single release.

The operator's real contribution is a shift in interface. You stop editing prometheus.yml and start declaring intent through CRDs; the operator generates the config and reloads Prometheus for you. What it cannot generate is anything about Harborline — your recording rules, your checkout SLO, your pages remain your work.

The One-Install Stack

The chart lives in the prometheus-community Helm repository and one helm install deploys the whole lineup: the operator, a Prometheus that can run 2 replicas, Alertmanager, Grafana, node_exporter on every node, and kube-state-metrics. Scraping of the kubelet, cAdvisor, and the control-plane components is preconfigured, so the entire built-in surface from the previous topic flows into the TSDB within one scrape interval of the install finishing.

The Operator Pattern, Aimed at Monitoring

The Prometheus Operator watches a family of CRDs — Prometheus, Alertmanager, ServiceMonitor, PodMonitor, PrometheusRule, Probe, ScrapeConfig, AlertmanagerConfig — and reconciles reality toward them. It generates the actual prometheus.yml from those resources, and a config-reloader sidecar hot-reloads Prometheus on every change. This is the same declare-and-reconcile loop the Kubernetes Deep Dive course teaches, aimed at monitoring.

The operator's reconcile loop — declare, generate, reload
Declare CRDsintent, in git
Operator watchesreconcile loop
Generates configprometheus.yml
Reloads Prometheushot, no restart

Reconciliation cuts both ways. Because the operator owns the generated config, editing it directly — or the Secret that holds it — accomplishes nothing: the operator writes its own version back within moments, without an error. The CRDs are the only interface that sticks, which is exactly what makes monitoring config reviewable in git instead of drifting on a server.

The Prometheus CRD as the Server Spec

Replicas, retention, resource requests, external labels, and which ServiceMonitors this server selects all live in one Prometheus resource. Extending retention from 15 to 30 days is a field edit and a reconcile, not an SSH session — the snippet below declares a 2-replica server keeping 30 days on a 100 Gi volume.

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata: {name: harborline}
spec:
  replicas: 2
  retention: 30d
  storage:
    volumeClaimTemplate:
      spec:
        resources: {requests: {storage: 100Gi}}

Bundled Dashboards and Rules

The chart ships the kubernetes-mixin dashboards — compute resources by namespace, pod, and node — plus dozens of alert rules: KubePodCrashLooping, CPUThrottlingHigh, NodeFilesystemSpaceFillingUp. One of them, Watchdog, fires permanently on purpose: it is a dead man's switch, and its absence at the receiving end is the signal that the alerting pipeline itself has died. That is a platform-monitoring baseline Mara does not have to write.

The CRD Upgrade Trap

Helm installs CRDs on first install but does not touch them on helm upgrade. Each major chart version therefore requires applying the new CRDs manually — kubectl apply --server-side from the matching release — before upgrading the chart. Skip it and the operator hits unknown fields and quietly stops reconciling parts of the config while every pod still reports Running.

What You Still Own

The operator automates config plumbing, not judgment. The harborline_ recording rules, the checkout SLO burn-rate alerts from Chapter 10, and the bookings and payments dashboards arrive as PrometheusRule resources and dashboard ConfigMaps that Mara writes, reviews, and version-controls exactly as before. The chart monitors the platform; monitoring the product is still your job.

Common Mistakes
  • Running helm upgrade across a major chart version without applying the new CRDs first — the operator logs unknown-field errors and silently stops reconciling parts of the config while everything looks Running.
  • Deleting the Watchdog alert as noise — it is the dead man's switch; when the pipeline breaks, its absence at the receiving end is the only alert you will get.
  • Editing the generated Prometheus config or the operator-owned Secret directly — the operator reconciles it back within moments, and the edit vanishes without an error.
  • Leaving the bundled alert rules unrouted so all several dozen fire into the same channel as the checkout SLO pages — platform noise buries user-pain signal, the exact failure Chapter 9 exists to prevent.
  • Shipping the chart's default retention and storage assumptions unchanged to production — without an explicit persistent volume, a pod reschedule empties the TSDB and the 28-day SLO window loses its history.
Best Practices
  • Install monitoring on Kubernetes via kube-prometheus-stack rather than hand-assembled manifests — the operator plus CRDs make scrape config, rule loading, and reloads declarative and reviewable.
  • Pin the chart version in your values repo and treat chart upgrades as reviewed changes with the CRD apply step, never a routine bump.
  • Keep every PrometheusRule and dashboard in git and deploy them through the same pipeline as application code — the CRD interface exists precisely so monitoring config can be code.
  • Set retention and persistent storage explicitly in the Prometheus CRD, sized to your SLO window — a 28-day SLO needs at least 28 days of data that survives pod reschedules.
Comparable toolsGKE Managed Service for Prometheus — managed collection, PromQL keptEKS Amazon Managed Prometheus + Managed GrafanaAKS Azure Monitor managed PrometheusSaaS Datadog / New Relic — a vendor DaemonSet replaces the chart, priced per host

Knowledge Check

Mara edits the generated Prometheus config Secret directly to add a scrape job. What happens?

  • Prometheus rejects the edit because the Secret is marked immutable
  • The operator overwrites her edit on the next reconcile, silently
  • The config-reloader sidecar crashes on the unexpected change
  • The job works permanently, since the Secret is the source of truth

What is the failure mode of running helm upgrade across a major chart version without applying the new CRDs?

  • Helm refuses to upgrade until the CRDs match and blocks the release until you patch them
  • Every Prometheus pod crash-loops immediately
  • The operator hits unknown fields and silently stops reconciling parts of the config
  • Grafana loses its bundled dashboards

Why does the chart ship a Watchdog alert that fires forever?

  • To indicate the cluster is under sustained load
  • Its absence at the receiving end is the signal that the alerting pipeline died
  • To exercise every Alertmanager route on a schedule
  • It is sample content meant to be deleted after install

After installing kube-prometheus-stack, which of these does Mara still have to build herself?

  • Scrape configuration for the kubelet, cAdvisor, and control-plane components
  • Host-level metrics collection on each node
  • Cluster capacity dashboards in Grafana
  • The checkout SLO burn-rate alerts and harborline_ recording rules

You got correct