Skip to content

Set Up Monitoring with Prometheus and Grafana

Easy ~35 min

What you'll build

A monitoring stack with Prometheus collecting metrics from your cluster and Grafana displaying them on a dashboard.

Goals

  • Deploy Prometheus in a Kubernetes cluster
  • Deploy Grafana and connect it to Prometheus
  • Create a Grafana dashboard to visualize cluster metrics
  • Understand how Prometheus scrapes metrics

Prerequisites

  • A Kubernetes cluster (or minikube) with kubectl
  • Helm installed
  • Basic understanding of metrics and monitoring concepts

Steps

  1. 1

    Add the Prometheus Helm repo

    Add the Prometheus community Helm chart repository and update your local chart cache.

    Code
    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    helm repo update

    Expected result

    The Prometheus Helm repository is added and updated.

  2. 2

    Install Prometheus

    Use Helm to install the Prometheus stack (includes Prometheus, Alertmanager, and Grafana) in a new namespace.

    Code
    kubectl create namespace monitoring
    helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring

    Expected result

    Prometheus and Grafana are deployed in the monitoring namespace.

  3. 3

    Access Grafana

    Port-forward the Grafana service to access it locally. The default username is 'admin' and password is 'prom-operator'.

    Code
    kubectl port-forward svc/prometheus-grafana -n monitoring 3000:80

    Expected result

    Open http://localhost:3000 and log in to Grafana with admin/prom-operator.

  4. 4

    Explore dashboards

    The kube-prometheus-stack comes with pre-built dashboards. Go to Dashboards in Grafana and explore the pre-configured Kubernetes monitoring dashboards.

    Expected result

    You see dashboards showing cluster CPU, memory, network, and Pod metrics.

  5. 5

    Add a health check endpoint

    Add a /health endpoint returning 200 OK for orchestration systems (Kubernetes, load balancers) to probe liveness. Health checks are foundational for production deployment.

    Code
    # app.py (Flask example)
    from flask import Flask, jsonify
    app = Flask(__name__)
    
    @app.route("/health")
    def health():
        return jsonify({"status": "ok"}), 200
    
    @app.route("/ready")
    def ready():
        # Check DB connection etc.
        return jsonify({"ready": True}), 200

    Expected result

    curl localhost:5000/health returns {"status":"ok"} with a 200 status code.

Try it yourself

What you learned

You deployed a full monitoring stack with Prometheus and Grafana. This gives you visibility into your cluster health and performance, which is essential for running production systems.

Related Resources

Related Glossary

Related Glossary

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to topic