Integration of Prometheus and Grafana and making their data persistent.

Anurag Mittal
6 min readJun 29, 2020

Lets discuss about the project-

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

Tools Required-

  1. Redhat VM
  2. Kubernetes
  3. jenkins
  4. Docker

Creating Dockerfile for prometheus.

I have created one metrics directory for storing metrics generated by Prometheus.

Similarly, we will create Grafana image on top of CentOS.

In this project I have uploaded the Prometheus — Dockerfile , prometheus-pv.yml, prometheus-pvc.yml, prometheus-deployment.yml on github by creating one repository for prometheus

https://github.com/anurag08-git/prometheus.git

I have uploaded the grafana— Dockerfile , grafana-pv.yml, grafana-pvc.yml, grafana-deployment.yml on github by creating one repository for grafana

https://github.com/anurag08-git/grafana.git

PROMETHEUS

Now we are going to creating our first job in jenkins.

1. This job will download the Prometheus — Dockerfile , prometheus-pv.yml, prometheus-pvc.yml, prometheus-deployment.ym from github repository.

2. Build the image by using prometheus-Dockerfile . Push this image to docker.hub.com .

3. Now by using prometheus-pv.yml file , it will create one Persistent Volume for Prometheus . We have given a storage capacity of 3 Gigabyte and an access mode of ReadWriteOnce. This PV will be used by PVC for getting the storage.

4. After this by using the file prometheus-pvc.yml , jenkins will create one Persistent Volume Claim for prometheus. This PVC will get the storage from PV that we have created .

5. Now by using file prometheus-deployment.yml , jenkins will create one deployment for the prometheus on the top of kubernetes.

In this job of jenkins we have to give the URL of the github repository where all the files for prometheus have uploaded.

This job will download the files from github and copy inside one folder. first build the Dockerfile, tag it and push it dockerhub

creating one pv — kubectl create -f prometheus-pv.yml

creating one pvc — kubectl create -f prometheus-pvc.yml

After this creating deployment for prometheus-- kubectl create -f prometheus-deployment.yml

Now expose this deployment to the outside world by creating one service- NodePort — kubectl expose deployment prometheus-deploy — type=NodePort — port=9090

output of this job -

Grafana

Now we are going to creating our second / final job in jenkins.

1. This job will download the Grafana— Dockerfile , grafana-pv.yml, grafana-pvc.yml, grafana-deployment.ym from github repository.

2. Build the image by using grafana-Dockerfile . Push this image to docker.hub.com .

3. Now by using grafana-pv.yml file , it will create one Persistent Volume for grafana. We have given a storage capacity of 2Gigabyte and an access mode of ReadWriteOnce. This PV will be used by PVC for getting the storage.

4. After this by using the file grafana-pvc.yml , jenkins will create one Persistent Volume Claim for grafana. This PVC will get the storage from PV that we have created .

5. Now by using file grafana-deployment.yml , jenkins will create one deployment for the grafana on the top of kubernetes.

In this job of jenkins we have to give the URL of the github repository where all the files for grafana have uploaded.

This job will run only when prometheus-job will build successful. We are doing this to create one chain between the jobs.

This job will download the files from github and copy inside one folder. first build the Dockerfile, tag it and push it dockerhub

creating one pv — kubectl create -f grafana-pv.yml

creating one pvc — kubectl create -f grafana-pvc.yml

After this creating deployment for grafana— kubectl create -f grafana-deployment.yml

Now expose this deployment to the outside world by creating one service- NodePort- kubectl expose deployment grafana-deploy — type=NodePort — port=3000.

output of this job -

As you can see images for Prometheus and Grafana have been pushed to docker hub successfully.

Now our all setup has been done properly. we can visualize this setup by creating one pipeline. Here I create one build pipeline for this setup. here is the is the beautiful output of the pipeline.

As you can see pods of grafana and prometheus are deployed successfully on top of kubernetes. All the resources that we have created for prometheus and grafana are deployed successfully on top of kubermetes.

The pod running with prometheus-

The pod running with grafana-

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Anurag Mittal
Anurag Mittal

Written by Anurag Mittal

Learning the new technologies like mlops, devops, hybrid multi cloud to enhance my skills.

No responses yet

Write a response