Skip to content
Prometheus & Grafana Operator Installation Lab

Prometheus & Grafana Operator Installation Lab

A lab guide for building and automating a monitoring system in a Kubernetes environment using the Operator pattern.


1. Lab Overview and Architecture

In this lab, instead of deploying Prometheus and Grafana manually, you will manage their lifecycle through Operators.

ComponentRoleNotes
Prometheus OperatorManages the Prometheus server, Alertmanager, and ServiceMonitorAutomatic target discovery
Grafana OperatorManages Grafana instances, DataSources, and DashboardsConfiguration automation
ServiceMonitorA CRD that defines which Services to scrape metrics fromCore configuration object

2. Overall Data Flow

    graph LR
    App[Application Pod] -- "Metrics" --> SM[ServiceMonitor]
    SM -- "Pass target info" --> PROM[Prometheus Server]
    PROM -- "Visualize data" --> GRAF[Grafana UI]
    
    subgraph Operators
    PO[Prometheus Operator] -.-> PROM
    GO[Grafana Operator] -.-> GRAF
    end
  

3. Installation Steps Summary

[Step 1] Create the Namespace

kubectl create namespace monitoring

[Step 2] Install Prometheus Operator (Helm)

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring

[Step 3] Install Grafana Operator (Helm)

# The Grafana Operator chart is published as an OCI artifact (no `helm repo add` needed)
helm install grafana-operator oci://ghcr.io/grafana/helm-charts/grafana-operator --namespace monitoring

4. Core Custom Resources

After installing the Operators, you manage configuration through the following Custom Resources (CRs).

Resource KindPurpose
PrometheusDefines the actual Prometheus server instance
ServiceMonitorSpecifies the Services (endpoints) to scrape metrics from
GrafanaDefines the Grafana server instance
GrafanaDatasourceConfigures the data sources (Prometheus, etc.) that Grafana connects to
GrafanaDashboardDeploys dashboards via JSON or a Grafana.com ID

5. Installation Order Workflow

    flowchart TD
    A[1. Create Namespace monitoring] --> B[2. Install Prometheus Operator]
    B --> C[3. Create Prometheus instance]
    C --> D[4. Register ServiceMonitor]
    D --> E[5. Install Grafana Operator]
    E --> F[6. Configure Grafana instance and DataSource]
    F --> G[7. Provision Dashboard]
  

6. Summary

With the Prometheus and Grafana Operators, you can avoid editing configuration every time a monitoring target is added: simply adding a ServiceMonitor resource automates metric collection. This demonstrates the core value of declarative infrastructure management.