Integration of Prometheus — Grafana-Kubernetes


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.

⚜️ 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:

For Grafana:

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

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

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

Step 3: Repeat step 2 for Grafana.

For this we need a PVC file first.

Now we will create the Grafana deployment file.

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

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 .

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

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

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

IP :

Grafana port : 30171 // in my case

Prometheus port : 30728 // in my case

Prometheus dashboard:-

Grafana Dashboard:-

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

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 ⚜️

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.