Integration of Prometheus — Grafana-Kubernetes

Anshika Sharma
5 min readSep 1, 2020

--

Logo

Hello guys!!!

In this blog we are going to create a great integration of Grafana-Kubernetes-Prometheus. We know that in today’s world where there is a huge data that need to be monitored. Suppose we have a website where a lot of people surfing and that surfing create logs, but think there will be huge logs. So is it possible to go through all this generated data in a thorough manner? Unfortunately the answer is “NO”. But what if we can visualize this data !! That will be so excieting. So lets create this integration for visualizing the logs.

Firstly, lets understand some deep concept about kubernetes , Prometheus and Grafana.

What is Kubernetes?

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

What is Prometheus and Grafana?

The combination of Prometheus and Grafana is becoming a more and more common monitoring stack used by DevOps teams for storing and visualizing time series data or the logs . Prometheus acts as the storage backend and Grafana as the interface for analysis and visualization of that data.

Sample Architecture

⚜️ Problem Statement:

Integrate Prometheus and Grafana and perform in following way:
1. Deploy them as pods on top of Kubernetes by creating resources Deployment, ReplicaSet, Pods or Services
2. And make their data to be remain persistent
3. And both of them should be exposed to outside world

Now lets start creating this integration step by step. Requirements to create the solution to this problem statement:

  1. We need to have separate docker image for Prometheus and Grafana.
  2. We will deploy pods for both on top of kubernetes using kubectl.
  3. PVC (Persistent volume claim) for both the deployments.
  4. kustomization file to create complete setup with single command.

Step 1: Create Dockerfile to create Docker image for Prometheus and Grafana.

For Prometheus:

Docker image code for Prometheus

For Grafana:

Docker image code for Grafana

Step 2: Now Creating yml file for deployment of Prometheus.

For this, we will create a PVC named pvc-prometheus.

PVC for Prometheus

Now we will create the deployment yml file, where we integrate this pvc.

prometheus-deploy.yml file

Step 3: Repeat step 2 for Grafana.

For this we need a PVC file first.

pvc for Graphana

Now we will create the Grafana deployment file.

grafana-deply.yml file

Step 4: Creating the kustomization file to setup everything with single command.

kustomization.yml file

The name of this file should be the same. Also the thing to be taken care is the sequence of listing of yml files in the kustomization.yml file i.e., pvc-for-prometheus.yml and pvc-for-grafana.yml file should be listed before prometheus-deploy.yml and grafana-deploy.yml file.

Step 5: Create the deployment using kustomization.yml file using command kubectl apply -k .

applying kustomization.yml file

Step 6: Access the complete information about the deployment we have created using “kubectl get all -o wide ” command.

Deploying the services, RS and pods

It will take some seconds to create the deployments and pods.

Successful Deployment

Step 7: Access Prometheus and Grafana through brower using the Exposed ports and minikube IP because we have launched our clusters over minikube.

IP : 192.168.99.110

Grafana port : 30171 // in my case

Prometheus port : 30728 // in my case

Prometheus dashboard:-

Prometheus graph page
Target page for Prometheus

Grafana Dashboard:-

Login Page for Grafana
Providing credentials
Grafana Dahboard
Adding data Source

Step 8: As our setup is done, its a good practice o clean up the environment. We will clean this complete environment using “kubectl delete -k . ” command

deleting deployment

Here, using a single command we have clean up the complete environment.

Hence, we have successfully did the setup for Prometheus and Grafana over Kubernetes. Feel free to reach for any query, i will be happy to help.

Thank you!!!

⚜️Keep Learning , Keep sharing ⚜️

--

--

Anshika Sharma
Anshika Sharma

Written by Anshika Sharma

I am a tech enthusiast, researcher and work for integrations. I love to explore and learn about the new technologies and their right concepts from its core.

No responses yet