Grafana is an open-source lightweight dashboard tool. It can be integrated with many data sources like Prometheus, AWS cloud watch, Stackdriver, etc.

In our previous posts, we have seen the following.

  1. Setup Prometheus on Kubernetes
  2. Setup Kube State Metrics
  3. Setup alert manager on Kubernetes

This tutorial explains the Grafana setup on a Kubernetes cluster. You can create dashboards on Grafana for all the Kubernetes metrics through prometheus.

Lets get started with the setup.

Step 1: Create file named grafana-datasource-config.yaml

vi grafana-datasource-config.yaml

Copy the following contents.

Note: The following datasource configuration is for prometheus. If you have more data sources, you can add more data sources with different YAMLs under data section.

apiVersion: v1
kind: ConfigMap
  name: grafana-datasources
  namespace: monitoring
  prometheus.yaml: |-
        "apiVersion": 1,
        "datasources": [
                "editable": true,
                "name": "prometheus",
                "orgId": 1,
                "type": "prometheus",
                "url": "http://prometheus-service.monitoring.svc:8080",
                "version": 1

Step 2: Create the configmap using the following command.

kubectl create -f grafana-datasource-config.yaml

Step 3: Create a file named deployment.yaml

vi deployment.yaml

Copy the following contents

apiVersion: apps/v1
kind: Deployment
  name: grafana
  namespace: monitoring
  replicas: 1
      app: grafana
      name: grafana
        app: grafana
      - name: grafana
        image: grafana/grafana:latest
        - name: grafana
          containerPort: 3000
            memory: "2Gi"
            cpu: "1000m"
            memory: "1Gi"
            cpu: "500m"
          - mountPath: /var/lib/grafana
            name: grafana-storage
          - mountPath: /etc/grafana/provisioning/datasources
            name: grafana-datasources
            readOnly: false
        - name: grafana-storage
          emptyDir: {}
        - name: grafana-datasources
              defaultMode: 420
              name: grafana-datasources

Step 4: Create the deployment

kubectl create -f deployment.yaml

Step 5: Create a service file named service.yaml

vi service.yaml

Copy the following contents. This will expose Grafana on NodePort 32000. You can also expose it using ingress or a Loadbalancer based on your requirement.

apiVersion: v1
kind: Service
  name: grafana
  namespace: monitoring
  annotations: 'true'   '3000'
    app: grafana
  type: NodePort  
    - port: 3000
      targetPort: 3000
      nodePort: 32000

Step 6: Create the service.

kubectl create -f service.yaml

Now you should be able to access the Grafana dashboard using any node IP on port 32000. Use the following default username and password to log in. Once you log in with default credentials, it will prompt you to change the default password.

User: admin
Pass: admin

Setup Kubernetes Dashbaords

There are many prebuilt Grafana templates available for various data sources. You can check out the templates from here.

Setting up a dashboard from a template is pretty easy. Follow the steps given below to setup a dashboard to monitor kubernetes deployments.

Step 1: Get the template ID from grafana public template. as shown below.


Step 2: Head over to grafana and select the import option.

image 1

Step 3: Enter the dashboard ID you got it step 1

image 2

Step 4: Grafana will automatically fetch the template from Grafana website. You can change the values as shown in the image below and click import.

image 3

You should see the dashboard immediately.

image 4


Grafana is a very powerful tool when it comes to dashboards. It is used by many organisations to monitor its workloads. Let us know how you are using Grafana in your organisation. Also let us know if you want to add more information to this article.

Setup Grafana On Kubernetes