
What is a ServiceMonitor?
- A ServiceMonitor is a CRD that defines a set of targets for Prometheus to monitor and scrape.
- It expresses scrape configuration (endpoints, path, interval, job label) in Kubernetes objects so you don’t edit Prometheus config files directly.
- The Prometheus Operator translates ServiceMonitor resources into Prometheus
scrape_configs.

- Deploy your application (Deployment + Service).
- Create a ServiceMonitor that selects the Service (via labels) and specifies endpoints (port, path, interval).
- The Prometheus Operator discovers the ServiceMonitor and adds targets to Prometheus’ scrape configuration.
- Service exposes the application on port 3000 with port name
weband labelsjob: node-apiandapp: api. - ServiceMonitor selects the Service by
matchLabels, setsjobLabel: job(so the Prometheus job name is taken from the Servicejoblabel), and configures endpoints (scrape interval and metrics path).
Prometheus discovers ServiceMonitors based on the Prometheus custom resource configuration. Check the Prometheus CR’s
serviceMonitorSelector and serviceMonitorNamespaceSelector to know which ServiceMonitors (labels and namespaces) your Prometheus instance will use. When using the kube-prometheus-stack Helm chart, ServiceMonitors often need the label release: prometheus.release: prometheus, ensure your ServiceMonitor includes that label.
Apply the manifests
Apply the Service and ServiceMonitor (together or separately):
serviceMonitor/default/api-service-monitor/0. A Deployment with multiple replicas will show multiple endpoints (one per pod).

job="node-api"). Example metric lines returned from Prometheus:
up{job="node-api"} — a value of 1 indicates a healthy scrape target.
Inspect the generated Prometheus configuration
The Prometheus Operator converts ServiceMonitors into scrape_configs. In the Prometheus UI → Status → Configuration, search for the job name (e.g., serviceMonitor/default/api-service-monitor/0) to view the generated config. This shows how your ServiceMonitor settings translate into Prometheus scrape settings and relabel rules.

Namespaces and labels matter. Prometheus discovers ServiceMonitors according to the Prometheus CR’s selectors—if your ServiceMonitor is in a different namespace or lacks the expected label, Prometheus will not pick it up. Also ensure required RBAC permissions are in place for Prometheus to read ServiceMonitor resources in the target namespaces.
- ServiceMonitors provide a declarative method to register Prometheus scrape targets in Kubernetes.
- Make sure the Prometheus CR’s
serviceMonitorSelectorandserviceMonitorNamespaceSelectorinclude the labels and namespaces of your ServiceMonitors. - Create Services with meaningful labels and named ports, then create ServiceMonitors that select those Services and define scrape parameters (path, port, interval, jobLabel).
- Verify in Prometheus UI → Status → Targets that the job and endpoints appear and metrics are being scraped.
- Prometheus Operator: https://prometheus-operator.dev
- kube-prometheus-stack Helm chart: https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
- Prometheus documentation: https://prometheus.io/docs/