How to install Prometheus and Grafana on Kubernetes with Helm
Installing Prometheus and Grafana on Kubernetes using Helm is a straightforward way to set up robust monitoring and visualization tools for your cluster. Helm charts simplify deployment, making configuring and managing these tools easy.
Prerequisites
- A running Kubernetes cluster.
kubectl
CLI configured to access your cluster.- Helm installed on your local system.
Step 1: Add the Helm repository
Add the Prometheus Community Helm charts repository:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
Step 2: Install Prometheus
- Install the Prometheus Helm chart:
helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
prometheus
: The release name.--namespace monitoring
: Creates a namespace for Prometheus.
- Verify the installation:
kubectl get all -n monitoring
You should see resources like pods, services, and deployments related to Prometheus.
Access Prometheus:
- Get the Prometheus server service details:
kubectl get svc -n monitoring
Use
kubectl port-forward
to access it locally:kubectl port-forward svc/prometheus-server -n monitoring 9090:80
Access Prometheus at
http://localhost:9090
.
Step 3: Install Grafana
- Install the Grafana Helm chart:
helm install grafana prometheus-community/grafana --namespace monitoring
- Verify the installation:
kubectl get all -n monitoring
You should see Grafana-related pods, services, and deployments.
Access Grafana:
- Get the Grafana admin password:
kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode
Forward the Grafana service port:
kubectl port-forward svc/grafana -n monitoring 3000:80
Open Grafana in your browser at
http://localhost:3000
and log in with:- Username:
admin
- Password: The value retrieved above.
- Username:
Step 4: Connect Prometheus to Grafana
- Open Grafana and go to Configuration > Data Sources.
- Click Add Data Source and select Prometheus.
- Configure the Prometheus URL:
- If Prometheus is accessible within the cluster, use
http://prometheus-server:80
. - Otherwise, use
http://localhost:9090
if you are using port forwarding.
- If Prometheus is accessible within the cluster, use
- Click Save & Test to verify the connection.
Step 5: Import pre-built dashboards
- In Grafana, go to Dashboards > Import.
- Enter a dashboard ID from Grafana's dashboard repository, such as
1860
for a Kubernetes cluster monitoring dashboard. - Select the Prometheus data source and click Import.
Step 6: Customize configurations (optional)
Customize Prometheus and Grafana configurations using Helm values:
- Create a
values.yaml
file:
prometheus:
alertmanager:
enabled: true
server:
persistentVolume:
size: 10Gi
grafana:
adminPassword: "customPassword"
persistence:
enabled: true
size: 5Gi
- Install with custom values:
helm install prometheus prometheus-community/prometheus -f values.yaml --namespace monitoring
helm install grafana prometheus-community/grafana -f values.yaml --namespace monitoring
Step 7: Monitor your cluster
- Access pre-configured dashboards in Grafana for metrics like resource usage, pod health, and cluster performance.
- Use Prometheus for querying detailed metrics directly.
-
Limitations of Prometheus Labels
Prometheus labels are a powerful feature used to add dimensional data to metrics. However, improper use or lack of understanding of their limitations can lead to inefficiencies, high resource consu...
Questions -
What are Prometheus Labels?
What are Prometheus labels? Prometheus labels are key-value pairs used to add metadata to metrics, making them more descriptive and allowing flexible queries. They enable Prometheus to organize, fi...
Questions -
What Are The 4 Types Of Metrics In Prometheus
Prometheus supports four main metric types, each suited for specific use cases. These types help capture various aspects of system performance and behavior. 1. Counter A counter is a cumulative met...
Questions -
What Is A Bucket In Prometheus?
In Prometheus, a bucket is a concept used in histograms to organize observed values into predefined ranges. Buckets are critical for tracking and analyzing the distribution of values, such as respo...
Questions