Skip to main content
In this lesson you will consume the Prometheus Operator like a platform user: install the operator bundle, create Prometheus custom resources (CRs), and let the operator reconcile those CRs into running monitoring workloads. The operator manages the generated StatefulSet and Prometheus configuration for you, so you do not hand-edit StatefulSets or manually reload Prometheus configuration. Instead, you declare intent via CRs (custom resources).

What you’ll learn

  • Install the Prometheus Operator bundle (CRDs + controller).
  • Create a Prometheus CR and a ServiceMonitor CR that the operator will reconcile.
  • Observe how the operator generates and manages the underlying StatefulSet and configuration.
  • Scale Prometheus by updating the Prometheus CR (not by editing generated workloads).

Prerequisites

  • kubectl configured to the target cluster
  • Network access to fetch the operator bundle
  • (Optional) Familiarity with Kubernetes CRDs and RBAC

Install the Prometheus Operator bundle

Set an environment variable pointing to the operator bundle release, then apply it with server-side apply:
We use --server-side because operator bundles often include very large CRD definitions. Server-side apply delegates the final object merge to the Kubernetes API server, avoiding heavy client-side serialization and improving compatibility with large or complex manifests.
The bundle will create CRDs, the operator Deployment, RBAC rules, a ServiceAccount, and other supporting resources. Example server response (trimmed):
This installation is platform-admin work: once the controller and CRDs are present, application teams can create Prometheus and ServiceMonitor CRs.

Wait for the operator to be ready

If you create CRs before the operator controller is running, those CRs will exist in the API but nothing will reconcile them into workloads. Wait for the operator Deployment rollout to complete:
Do not create Prometheus CRs until the operator Deployment is Ready. CRs created while the controller is down will not be reconciled into StatefulSets until the controller is running.

Key CRDs used

Create a Prometheus CR

Inspect and apply a manifest that creates a ServiceAccount, a minimal ClusterRole, and a Prometheus custom resource named demo. The Prometheus CR uses a serviceMonitorSelector to pick up matching ServiceMonitor objects. prometheus.yaml:
Apply the manifest:
The operator will generate a StatefulSet for this Prometheus instance (for example prometheus-demo). Wait for the StatefulSet to be created and become ready:
Notes:
  • The operator generates the StatefulSet and related Pod spec. The Prometheus Pod often includes helper containers such as a config-reloader alongside the Prometheus binary.
  • You should not edit generated StatefulSets directly; edit the Prometheus CR and let the operator reconcile changes.

Create a ServiceMonitor to define scrape targets

A ServiceMonitor describes the endpoints Prometheus should scrape. It uses labels that match the Prometheus serviceMonitorSelector, so the operator can wire the scrape configuration automatically. servicemonitor.yaml:
Apply the ServiceMonitor:
Verify that the label on the ServiceMonitor matches the Prometheus serviceMonitorSelector:
They should both contain the same label (for example team: demo). That label equality is how the Prometheus instance selects which ServiceMonitors to include in its generated configuration.

Scale Prometheus by patching the CR

To change the replica count, patch the Prometheus CR. The operator will update the generated StatefulSet to match the desired replica count. Patch to request two replicas and wait for the StatefulSet rollout:
Confirm desired vs ready replicas:
The first number is the desired replica count (spec.replicas). The second number is how many replicas are currently ready (status.readyReplicas). This demonstrates the consumer-side operator pattern: modify the CR and let the operator manage generated workloads.

Quick checklist

  • Operator bundle applied (CRDs + controller).
  • Operator Deployment rollout completed.
  • Prometheus CR created with serviceMonitorSelector.
  • ServiceMonitor created with matching label(s).
  • StatefulSet generated and Pods are ready.
  • Scale or update by patching the Prometheus CR.
That covers the Prometheus Operator workflow: install the operator, create Prometheus and ServiceMonitor CRs, and manage your monitoring instance via CRs rather than directly editing generated Kubernetes workloads.

Watch Video

Practice Lab