Prometheus Architecture, ServiceMonitors & PodMonitors
Scrape Kubernetes workloads with Prometheus and operator-managed monitors.
In plain words
Prometheus is a scheduled gauge reader, and monitors are address lists telling it which storefronts to visit. The simple Kubernetes rule is: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
Think of it like…
Prometheus is a scheduled gauge reader, and monitors are address lists telling it which storefronts to visit.
Where you’ve seen it
An SRE testing a diagnosis runs kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090. Expected evidence: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets. If the run instead shows this symptom, stop and restore the last known state: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series.
Words you’ll hear
- Prometheus
- For this lesson, Prometheus is the controlling idea: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- ServiceMonitor
- ServiceMonitor is the checkpoint; run
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090and inspect the owner chain. An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series. - PodMonitor
- PodMonitor is the outcome to preserve; the cost is explicit: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.
- Verification evidence
- The evidence command is
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090. It connects the declaration to this behavior: Scrape Kubernetes workloads with Prometheus and operator-managed monitors.
Visual diagram
Theory & deep dive
How Prometheus reaches the intended state
Scrape Kubernetes workloads with Prometheus and operator-managed monitors. Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
The concrete checkpoint is kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090; compare the Prometheus owner, ServiceMonitor state, and PodMonitor outcome instead of treating YAML acceptance as proof.
Run kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090 after the change and correlate the result with Events and the owning object. Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
ServiceMonitor: failure boundary and production cost
An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series. The prerequisite contract is concrete: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time. A safe design limits blast radius, records the last good configuration, and uses kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090 as a deterministic rollback checkpoint.
Capture the current state with kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090, then correct the controlling manifest rather than patching a child object; the relevant divergence signal is specific: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series.
How it works, step by step
Step 1 of 41. Define the symptom and SLI
Turn the user symptom into a measurable question and select a telemetry source: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- Goal
- Scrape Kubernetes workloads with Prometheus and operator-managed monitors.
- Owner
- Prometheus
When to use it & trade-offs
What it is
Scrape Kubernetes workloads with Prometheus and operator-managed monitors. Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
Why it matters: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series. The invariant at risk is specific: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets. The quickest fact check before changing the design is kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090.
When to reach for it
- Use Prometheus to enforce this invariant: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- Use ServiceMonitor evidence from
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090in reviews and incident timelines. Scrape Kubernetes workloads with Prometheus and operator-managed monitors. - Choose the managed observability backend route only when this cost is justified by governance or scale: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.
When to avoid or be careful
- Avoid assuming Prometheus is complete after YAML submission; the required behavior is concrete: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- Avoid treating the next symptom as random; check the owner and state with
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090first: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series. - Avoid adopting a heavier platform wrapper before measuring its cost: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.
Native, manual, and managed paths for Prometheus
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090.Strengths: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
Watch out: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time. Recovery must also recognize this signal: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series.
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090; the expected invariant is: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.Strengths: kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090 gives immediate feedback without first building a platform layer.
Watch out: A manual change can hide drift, and unlike Prometheus, it does not make this symptom self-documenting: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series.
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090.Strengths: Platform controls can wrap this exact behavior in policy or dashboards: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
Watch out: The added platform ownership buys value at this cost: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.
Interview signals & numbers to know
When this topic comes up
- Interview anchor: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- Trace Prometheus to PodMonitor through ServiceMonitor; the invariant is: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- Recognize the symptom: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series.
- Justify the cost: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.
- Verify with kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090 instead of only inspecting YAML.
Benchmarks & rules of thumb
- 1
- Prometheus sample is a timestamp, value, and label set
- 2
- target-discovery CRDs are ServiceMonitor and PodMonitor
- 0
- deployment means no instance can scrape a target without an owner selector
Common mistakes & follow-ups
Common interview mistakes
- Debugging only the child object misses the Prometheus owner contract: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets.
- Ignoring this telltale condition leads to unrelated changes: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series.
- Repeating
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090without an owner for remediation wastes retry cost. Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.
Likely interviewer follow-ups
- How would API output and runtime evidence prove this behavior: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets?
- Which owner object, logs, and Events would you inspect for this symptom-An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series-?
- At what threshold would this cost become unacceptable: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time?
kubectl get prometheus,servicemonitor,podmonitor -A; kubectl port-forward svc/prometheus-operated 9090, name the failure, then justify the cost. Invariant: Prometheus scrapes /metrics targets, evaluates rules, and persists time series; ServiceMonitor and PodMonitor CRDs let Prometheus Operator select Services or Pods and relabel targets. Failure: An unready Prometheus CR or selector mismatch yields no targets even when endpoints exist, while relabeling can accidentally drop labels or duplicate every Pod series. Cost: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Prometheus Architecture, ServiceMonitors & PodMonitors with generative AI interview Q&A and hands-on practice.