Integration of Prometheus and Grafana and making their data persistent.

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-
- Redhat VM
- Kubernetes
- jenkins
- 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

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

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-
