This guide explains how to install Prometheus and Grafana in a Kubernetes cluster using Helm charts.
Before you begin, ensure the following:
- A running Kubernetes cluster.
kubectl
CLI installed and configured.- Helm CLI installed (version 3 or later).
Add the Prometheus and Grafana Helm chart repositories:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
-
Create a dedicated namespace for monitoring components:
kubectl create namespace monitoring
-
Install Prometheus using the
kube-prometheus-stack
Helm chart:helm install prometheus prometheus-community/kube-prometheus-stack \ --namespace monitoring
-
Verify the Prometheus installation:
kubectl get pods -n monitoring
-
Install Grafana in the same namespace:
helm install grafana grafana/grafana \ --namespace monitoring
-
Verify the Grafana installation:
kubectl get pods -n monitoring
-
Retrieve the Grafana admin password:
kubectl get secret grafana -n monitoring -o jsonpath="{.data.admin-password}" | base64 --decode
The default username is
admin
.
-
Prometheus:
- Forward the Prometheus service port:
kubectl port-forward svc/prometheus-kube-prometheus-prometheus -n monitoring 9090:9090
- Open your browser and navigate to
http://localhost:9090
.
- Forward the Prometheus service port:
-
Grafana:
- Forward the Grafana service port:
kubectl port-forward svc/grafana -n monitoring 3000:80
- Open your browser and navigate to
http://localhost:3000
.
- Forward the Grafana service port:
-
Login to Grafana using the admin credentials retrieved earlier.
-
Add Prometheus as a data source:
- Navigate to Configuration → Data Sources → Add Data Source.
- Select Prometheus.
- Set the URL to
http://prometheus-kube-prometheus-prometheus.monitoring.svc.cluster.local:9090
. - Click Save & Test.
-
Import Prebuilt Dashboards:
- Go to Create → Import.
- Enter the Dashboard ID from Grafana's Dashboard Library.
- Example: Use Dashboard ID
315
for Kubernetes cluster monitoring.
To uninstall Prometheus and Grafana:
-
Uninstall Prometheus:
helm uninstall prometheus -n monitoring
-
Uninstall Grafana:
helm uninstall grafana -n monitoring
-
Delete the monitoring namespace:
kubectl delete namespace monitoring
- Ensure sufficient resources are allocated to your Kubernetes cluster for running Prometheus and Grafana.
- Use PersistentVolumes if you need long-term data storage for Prometheus or Grafana configurations.
- Secure Grafana with Single Sign-On (SSO) or by enabling HTTPS for production use.