Set Up Monitoring with Prometheus and Grafana
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
Add the Prometheus Helm repo
Add the Prometheus community Helm chart repository and update your local chart cache.
Codehelm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo updateExpected result
The Prometheus Helm repository is added and updated.
- 2
Install Prometheus
Use Helm to install the Prometheus stack (includes Prometheus, Alertmanager, and Grafana) in a new namespace.
Codekubectl create namespace monitoring helm install prometheus prometheus-community/kube-prometheus-stack -n monitoringExpected result
Prometheus and Grafana are deployed in the monitoring namespace.
- 3
Access Grafana
Port-forward the Grafana service to access it locally. The default username is 'admin' and password is 'prom-operator'.
Codekubectl port-forward svc/prometheus-grafana -n monitoring 3000:80Expected result
Open http://localhost:3000 and log in to Grafana with admin/prom-operator.
- 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
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}), 200Expected 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
- Prometheus
Metrics collection system
- Grafana
Visualization and dashboards
Related Glossary
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
- Prometheus
Metrics collection system
- Grafana
Visualization and dashboards
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.