Interview's MateKubernetes
Interview's Mate

Kubernetes

K8s · Workloads · GitOps · Cloud

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Kubernetes topics
Lesson 122/ 160
07. Observability, Troubleshooting & SRE

Prometheus Architecture, ServiceMonitors & PodMonitors

Scrape Kubernetes workloads with Prometheus and operator-managed monitors.

IntermediatePrometheus · ServiceMonitor · PodMonitor3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 9090 and 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

Loading interactive 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.

Verify ServiceMonitor, not only object creation

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.

Key takeaway: Prometheus is implemented only when this invariant remains observable: 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.

Recover from ServiceMonitor drift

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.

Key takeaway: Accept the trade-off consciously: Operator-managed discovery reduces config drift, but cardinality from labels and multi-replica scraping can consume memory and query time.

How it works, step by step

Step 1 of 4
SRE and service owner

1. 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.

Prometheus contract → owned state
Key numbers at this step
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 9090 in 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 9090 first: 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

Metrics and evidence-led diagnosis
Best for: Scrape Kubernetes workloads with Prometheus and operator-managed monitors. A concrete incident check is 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.

Ad-hoc console inspection
Best for: Quickly testing the ServiceMonitor assumption with 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.

Managed observability backend
Best for: Teams that need PodMonitor integrated with guardrails; the evidence path is 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 9090 without 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?
Interview tip: Interview sequence: state the invariant, run 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

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Prometheus Architecture, ServiceMonitors & PodMonitors with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
The Three Pillars of Observability in Kubernetes (Metrics, Logs, Traces)
Next topic
PromQL Essentials for Cluster & Application Alerting