How to install Prometheus and Grafana on Kubernetes with Helm

Better Stack Team
Updated on November 29, 2024

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

  1. A running Kubernetes cluster.
  2. kubectl CLI configured to access your cluster.
  3. 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

  1. 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.
  1. Verify the installation:
 
   kubectl get all -n monitoring

You should see resources like pods, services, and deployments related to Prometheus.

  1. 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

  1. Install the Grafana Helm chart:
 
   helm install grafana prometheus-community/grafana --namespace monitoring
  1. Verify the installation:
 
   kubectl get all -n monitoring

You should see Grafana-related pods, services, and deployments.

  1. 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.

Step 4: Connect Prometheus to Grafana

  1. Open Grafana and go to Configuration > Data Sources.
  2. Click Add Data Source and select Prometheus.
  3. 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.
  4. Click Save & Test to verify the connection.

Step 5: Import pre-built dashboards

  1. In Grafana, go to Dashboards > Import.
  2. Enter a dashboard ID from Grafana's dashboard repository, such as 1860 for a Kubernetes cluster monitoring dashboard.
  3. Select the Prometheus data source and click Import.

Step 6: Customize configurations (optional)

Customize Prometheus and Grafana configurations using Helm values:

  1. Create a values.yaml file:
 
   prometheus:
     alertmanager:
       enabled: true
     server:
       persistentVolume:
         size: 10Gi

   grafana:
     adminPassword: "customPassword"
     persistence:
       enabled: true
       size: 5Gi
  1. 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.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.