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.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 nameddemo. The Prometheus CR uses a serviceMonitorSelector to pick up matching ServiceMonitor objects.
prometheus.yaml:
prometheus-demo). Wait for the StatefulSet to be created and become ready:
- 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 PrometheusserviceMonitorSelector, so the operator can wire the scrape configuration automatically.
servicemonitor.yaml:
serviceMonitorSelector:
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: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.
Links and references
- Prometheus Operator releases: https://github.com/prometheus-operator/prometheus-operator/releases
- cert-manager (optional integration): https://cert-manager.io/docs/
- Kubernetes Concepts: https://kubernetes.io/docs/concepts/