Setting up Grafana(3.2)

This page describes the setting up of the Grafana tool on your cluster to help visualize the metrics retrieved by the Prometheus server.

It also contains example dashboards both as zip and yaml-files that you can download:

grafana-dashboards.zip

grafana-dashboards.yaml

On Private Cloud and AWS

We will go through the steps for installing the Grafana tool using helm as well as how to integrate it with your  deployment. Before moving further, you can read up more on how to install Grafana using helm from https://github.com/grafana/helm-charts/tree/main/charts/grafana.

Before installing Grafana, it is recommended that you install the Prometheus server first. Refer to Setting up Prometheus(3.2) for more information.

Note!

The following is just one of many ways to install Grafana. The example provided uses the helm charts to install Grafana. However, you can install Grafana using any method you want.

Note!

If you have installed your Prometheus server in its own namespace, make sure that Grafana has access to the Prometheus server.

Installing Grafana without Persistence

The following steps show how to install Grafana without the use of persistence. This means that if your deployment is brought down the data is not retained. We do not recommend deploying Grafana without persistence in a production environment.

  1. Add the helm repo for Grafana.

    helm repo add grafana https://grafana.github.io/helm-charts
  2. To view data in Grafana you need to create one or more "dashboards". You can create them manually in the Grafana GUI or use a yaml file to create them in advance. This yaml file, grafana-dashboards.yaml, includes three pre-created dashboards for pico statistics, workflows, and MIMs. You can also provide your own yaml file with your own dashboard and data source configuration for this installation. You need to link the Prometheus server as your data source.

  3. Install Grafana using the helm install command. This example shows how to install Grafana in its own namespace called Grafana. Enter the Grafana node port number. If you have another dashboard yaml file, you can replace the value by <dashboard yaml name>.

    helm install -n <namespace> grafana grafana/grafana \ 
      --set service.type=NodePort \ 
      --set service.nodePort=<port> \
      -f ./<dashboard yaml name>

    Example: helm install Grafana

    helm install -n grafana grafana grafana/grafana \ 
      --set service.type=NodePort \ 
      --set service.nodePort=30090 \
      -f ./grafana-dashboards.yaml

Installing Grafana with Persistence

The following steps show how to install Grafana with the use of persistence volumes on your Kubernetes cluster.

  1. Create a yaml file and describe the Persistent Volume and Persistent Volume Claim for Grafana. The example used here creates the persistent volume on an NFS file server that is mounted onto the cluster. The value set in nfs.path is the directory on the NFS file server that stores the data for Grafana.

    Example: Persistence for Grafana

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: grafana
    spec:
      accessModes:
      - ReadWriteMany
      capacity:
        storage: 10Gi
      nfs:
        path: /export/snap/metrics/grafana
        server: files.dev.drint.net
      persistentVolumeReclaimPolicy: Retain
      storageClassName: grafana-persistent
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: grafana-persistent
    spec:
      accessModes:
      - ReadWriteMany
      resources:
        requests:
          storage: 10Gi
      storageClassName: grafana-persistent
  2. After creating the yaml file, run this command:

    kubectl apply -f <persistent volume yaml> -n <namespace>
  3. Add the helm repo for Grafana.

    helm repo add grafana https://grafana.github.io/helm-charts
  4. To view data in grafana you need to create one or more "dashboards". You can create them manually in the Grafana GUI or import them from json based definition files. This zip file, grafana-dashboards.zip, includes three pre-created dashboards for pico statistics, workflows, and MIMs. You need to link the Prometheus server as your data source.

  5. Install Grafana using the helm install command. In this example, Grafana is installed in its own namespace called grafana. Enter the Grafana node port number. Set the name of the Persistent Volume Claim that you have created in the previous steps.
    If you have another dashboard yaml file, you can replace the value by <dashboard yaml name>.

    helm install -n <namespace> grafana grafana/grafana \ 
      --set service.type=NodePort \ 
      --set service.nodePort=<port> \ 
      --set persistence.enabled=true \ 
      --set persistence.accessMode=ReadWriteMany \ 
      --set persistence.storageClass=grafana-persistent \ 
      --set persistence.existingClaim="grafana-persistent" \
      -f ./<dashboard yaml name>

    Example: helm install Grafana - with persistence

    helm install -n grafana grafana grafana/grafana \ 
      --set service.type=NodePort \ 
      --set service.nodePort=30090 \ 
      --set persistence.enabled=true \ 
      --set persistence.accessMode=ReadWriteMany \ 
      --set persistence.storageClass=grafana-persistent \ 
      --set persistence.existingClaim="grafana-persistent" \
      -f ./grafana-dashboards.yaml

Verify the Grafana Installation

This step shows how to check that your Grafana is deployed correctly.

  1. After installing Grafana you are given an export command to use to acquire the URL and the Port of the Grafana GUI. The command looks something like this:

    export NODE_PORT=$(kubectl get --namespace <namespace> -o jsonpath="{.spec.ports[0].nodePort}" services grafana)
    export NODE_IP=$(kubectl get nodes --namespace <namespace> -o jsonpath="{.items[0].status.addresses[0].address}")

    Example: Exporting the value for Grafana Node IP and Node Port

    $ export NODE_PORT=$(kubectl get --namespace grafana -o jsonpath="{.spec.ports[0].nodePort}" services grafana)
    $ export NODE_IP=$(kubectl get nodes --namespace grafana -o jsonpath="{.items[0].status.addresses[0].address}")
  2. To generate the URL from the result of the two export commands above, use this echo command. Then copy the result to your browser.

    echo http://$NODE_IP:$NODE_PORT

    Example: Url for Grafana GUI

    http://192.168.52.26:30090
  3. Find the password of the admin user for Grafana. After installing Grafana, you are prompted with a message informing you how to retrieve the password. This is an example of what it can look like:

    Example

    kubectl get secret --namespace <namespace> grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

    Note!

    If you do not have the password randomly assigned you can manually define the default admin username and password with extra variables when you run the helm install command. See the example values.yaml on https://github.com/grafana/helm-charts/blob/main/charts/grafana/values.yaml.