Deploying Grafana to Kubernetes

Aymen El Amri
The MetricFire Blog

--

Table of Contents

  1. Introduction
  2. The basics of Grafana
  3. Creating a Kubernetes cluster
  4. Creating a Grafana Service
  5. Testing Grafana
  6. Extending Grafana
  7. Storage
  8. Conclusion

1. Introduction

Grafana is an open-source platform for metric analytics, monitoring, and visualization. In this article, we will explore the basics of Grafana and learn how to deploy it to Kubernetes. You will find specific coding examples and screenshots you can follow to deploy Grafana. For full code snippets, see the article on the MetricFire website.

2. The Basics of Grafana

Before we dive into our code, you should be familiar with what Grafana can do for you. Grafana pulls up metrics from different data sources. For each source, it has a specific syntax and query editor that extracts and interprets data.

Grafana supports multiple data sources like Prometheus, Mysql, MSSQL, PostgreSQL, Influx DB, Graphite, and ElasticSearch. It can also load data from some cloud-managed services like Google Stackdriver, Azure Monitor, and AWS CloudWatch. With the right plugin, you can even extend Grafana and add other data stores and online sources. Time series data for infrastructure and applications (such as disk I/O utilization, CPU, and memory) is first loaded into the analysis tool, then analyzed.

Furthermore, Grafana allows you to easily create and edit dashboards.

3. Creating the Kubernetes Cluster

To better understand how Grafana works, we are going to use it to monitor a Kubernetes cluster. You can use any managed cloud cluster or even Minikube. In this tutorial, we are going to use GKE (Google Kubernetes Engine), the managed Kubernetes service of Google Cloud. If you are using GKE, your Google Cloud project should be linked to a billing account. You should also enable the Kubernetes API and install Google Cloud SDK.

If you are going to use another cloud provider, you can follow almost the same steps shown here, except for some commands specific to Google Cloud Platform (GCP).

Once installations and configurations are done, you can proceed by using:

gcloud container clusters create mycluster --zone europe-west1-b

Change “mycluster” for a cluster name of your choice and make sure to use your preferred zone.

Alternatively, if you are using a Minikube cluster, you should first install it by following the official instructions. Then, create a cluster using:

minikube start

‍Now that the cluster is up and running, we need to install the Kubernetes command-line tool, kubectl. The installation is quite simple. If you are using Debian/Ubuntu, you need to run these commands:

4. Create a Grafana Service

We are going to use the official Grafana image (v5.4.3) from Docker Hub to create a deployment.

kubectl create deployment grafana --image=docker.io/grafana/grafana:5.4.3

‍You can check if the image was deployed by using:

kubectl get deployments

You should see an output similar to the following:

NAME    READY UP-TO-DATE AVAILABLE AGE
grafana 1/1 1 1 66s

In order to access the Grafana dashboard, its service should be reachable from outside the cluster. However, after creating the deployment, Grafana is only accessible from inside the cluster because it uses a ClusterIP …

To read the rest of this article, check out the full length post on the MetricFire website.

--

--