Grafana is an open-source dashboard tool that can be used to display metrics of different systems. It can be integrated with a variety of data sources like Prometheus, InfluxDB Stackdriver, etc.

Grafana uses time series data for infrastructure and applications (such as disk I/O utilization, CPU, and memory) that is first loaded into the analysis tool, e.g Prometheus, then analyzed.

This post explains how to setup a Grafana dashboard on Kubernetes using Prometheus as the data analytics tool.

The steps below will guide us on how to configure a working Grafana instance on an existing Kubernetes cluster.

You can follow the posts below if you wish to deploy a kubernetes cluster:

With your Kubernetes cluster installed and fully functional, proceed to the next configuration steps.

1: Deploy Grafana Service in Kubernetes

Create new project for the deployment:

$ kubectl create namespace monitoring
namespace/monitoring created

Deploy Grafana service into the namespace we just created.

$ kubectl create deployment grafana -n monitoring --image=docker.io/grafana/grafana:latest
deployment.apps/grafana created

This deploys Grafana on the cluster and starts it. After a few seconds, you can check if the image was deployed by using:

$ kubectl get deployments -n monitoring

The output will be something similar to this:

$ kubectl get deployments -n monitoring
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
grafana   1/1     1            1           21s

2. Expose Grafana Service using NodePort

We have to expose grafana service via the NodePort as it is only accessible using ClusterIP currently.
Expose the grafana deployment using NodePort service with the following command:

$ kubectl -n monitoring expose deployment grafana --type="NodePort" --port 3000
service/grafana exposed

This creates a service and exposes port 3000, the default grafana port.

Check if the service has been exposed with the following command:

$ kubectl get service -n monitoring
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
grafana      NodePort    10.96.174.231   <none>        3000:32150/TCP   9s

We use the describe service command to find which port has been exposed externally.

[email protected]:~# kubectl describe service grafana
Name:                     grafana
Namespace:                default
Labels:                   app=grafana
Annotations:              <none>
Selector:                 app=grafana
Type:                     NodePort
IP:                       10.152.183.50
Port:                     <unset>  3000/TCP
TargetPort:               3000/TCP
NodePort:                 <unset>  32150/TCP
Endpoints:                10.1.196.7:3000
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

Grafana is now exposed to port 32150 and can be accessed via that port externally.

3. Access Grafana Web Dashboard

You can now open the Grafana dashboard in the browser using http://<master_IP>:NodePort. e.g:

http://172.21.200.11:32150

This opens a Grafana login page. The default username and password for Grafana is admin/admin

kubernetes grafana

You will be asked to change the password on your first-time login.

grafana kuberenetes 1

We need to test our Grafana instance to find out if it is working as expected. The simplest method to test that is to use theTestData DB method which provides a sample of the visualized data.

grafana kubernetes create datasource 1

Click ‘Create your first data source’ tab then choose ‘TestData DB’. Click ‘Save and test’ as shown below.

kubernetes grafana choose datasource

Click ‘Create a new dashboard’ to create a dashboard.

create dashboard kubenetes grafana

To see a panel with visualized data, click on ‘heat map’ or ‘graph’

sample heatmap gafana kubernetes

There are many prebuilt Grafana templates available for various data sources. These templates can be used to create user-friendly dashboards that have the pre-built functionalities which fit your environment.

You can check out the templates from here.

The steps below will guide us on how to monitor our Kubernetes cluster with the Grafana instance we just deployed.

1 Obtain the template ID from grafana public template as shown:

Kuberenetes dashboadr download

2. Select the Import option from your Grafana dashboard.

import option grafana

3. Enter the dashboard ID obtained from Grafana

import dashboard grafana

4. Click Load button:

import dashboard2 graana

5. Click import to import the dashboard. This will redirect to the dashboard with the metrics displayed as in the sample below:

Kubernetes cluster monitoring

To get more metrics on your kubernetes cluster you need to integrate exporters like Prometheus and Kube State Metrics.

These will be covered in other articles on this site.

Conclusion

Grafana is a very lightweight yet powerful tool when it comes to dashboards. It can be integrated with several monitoring tools and can be very useful for visualization of different workloads in different scenarios. This includes cloud systems, network environments and containers.

More guides:

Deploying Prometheus on EKS Kubernetes Cluster

Install Kubernetes Metrics Server on Amazon EKS Cluster

Visualize & Monitor Kubernetes workloads with VMware Octant

Install Lens – Best Kubernetes Dashboard & IDE

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

LEAVE A REPLY

Please enter your comment!
Please enter your name here