Integration of Prometheus and Grafana over Kubernetes.

Preface.

Grafana is an open-source, general-purpose dashboard and graph composer, which runs as a web application. Grafana allows you to query, visualize, alert on and understand your metrics no matter where they are stored. Create, explore, and share dashboards with your team and foster a data-driven culture.

Prometheus is an open-source system monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company.

In this article, we will deploy Grafana & Prometheus as Kubernetes pods and connect them. I will use Minikube, in this.

Problem Statement….

  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

Here the task begins…

  1. First we have to create the 2 docker images in which prometheus and grafana were installed.

This is the Dockerfile of Grafana…

After saving this file we have run this cmd….

docker build -t grafana:v1 /grafana/

Here it build successfully…

Now we have push this image to Dockerhub.

Now again for Prometheus image

This is the Dockerfile of prometheus..

Again run this cmd..

docker build -t prometheus:v1 /prometheus/

Again this image is also successfully build.

Now here the time come to push this image into Dockerhub.

Now, we have to create the yml files for deploying it.

  1. Creating a Persistent Volume on kubernetes that will be used for storing data for both prometheus and grafana.

Prometheus-pv.yml

Grafana-pv.yml

2. Creating a Persistent Volume Claim on Kubernetes that will provide the storage for storing data for both Prometheus and Grafana.

Prometheus-pvc.yml

Grafana-pvc.yml

3. Creating a deployment for both prometheus and grafana that will create the pod, mount the pv.

Prometheus-deploy.yml

Grafana-deploy.yml

Now here is the kustomization file.

Here all the yml files are created.

Now we have to first start our minikube by run this cmd in command prompt.

minikube start

After that we have to run this cmd.

kubectl create -k .

After this we have to expose our pods.

For this we have to run this……

kubectl expose deployment prom-deploy --port=9090 --type=NodePort


kubectl expose deployment grafana-deploy --port=3000 --type=NodePort

Now check that your pods are ready or not by run this cmd….

kubectl get pods

kubectl get all

At last go to the exposed IP address and see the output…….

Thats all about my Task

Github link- https://github.com/abhi-85/Devops-task5

Thank you for reading……..

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store