Save your Grafana & Prometheus Data With Kubernetes Using Pvc & ConfigMap

Manas Jain
FAUN — Developer Community 🐾
5 min readAug 4, 2020

--

In this Article I Will cover how to make data persistent with the help of Kubernetes PVC and Config Map

What is Prometheus?

Prometheus is an open-source software application used for event monitoring and alerting. It records real-time metrics in a time series database (allowing for high dimensionality) built using an HTTP pull model, with flexible queries and real-time alerting. It is now a standalone open source project and maintained independently of any company

source — https://prometheus.io

What is Grafana?

Grafana is an open-source solution for running data analytics, pulling up metrics that make sense of the massive amount of data & to monitor our apps with the help of cool customizable dashboards.

Grafana connects with every possible data source, commonly referred to as databases such as Graphite, Prometheus, Influx DB, ElasticSearch, MySQL, PostgreSQL, etc.

Grafana being an open-source solution also enables us to write plugins from scratch for integration with several different data sources.

The tool helps us study, analyze & monitor data over a period of time, technically called time-series analytics

source -https://grafana.com/

Start From Here so First we’ll create Prometheus YML file

So, First of all, we have to create PVC For Prometheus

after creating this file run this below command and this command will create PVC

kubectl apply -f promethusPVC.yml #filename.yml

So after creating PVC now we need something where we mount this PVC so obviously we want PODS with some Powers like Deployment & ReplicaSet

Here I use my Own Docker Image & the Config Map? So what is ConfigMap

It is used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume

So we have to create Configmap file for Prometheus so we can provide some information from the outside with the help of configMap

kubectl apply -f configprom.yml #first create configmap
--------------------------------
kubectl apply -f promedeploy.yml # then run this deployment file

in the deployment file of Prometheus, we also have created service in the last this service or nodePort will help us to connect this Prometheus through URL.

Run this command below to check IP Of Node and the service port where Prometheus is running

minikube ip && kubectl get svc 

So After the visit on this URL Output Something Like this

So here the mount Path of PVC Where the data

Grafana

Creating PVC for Grafana Pod

After This Run This below command

kubectl apply -f grafavol.yml #file_name.yml

then create the deployment of Grafana

Then again run the command to know about service port and Node Ip

minikube ip && kubectl get svc

So After the visit on this URL Output Something Like this

☝️ This Is the first login screen of Grafana. the default username & password is “admin”

After entering the username and password it asks you to enter a new password so choose accordingly

so now you’ve logged in successfully

So Prometheus and Grafana are running on Kubernetes with the persistent data so if any issue occurs happens it may destroy the pod and after launching a new one, the previous data won't be lost. It auto-updates the previous data with data so we don't face any issue.

Now let's Check if Our data is consistent or not with Grafana

So firstly we will create a dashboard in Grafana and connect the data source as Prometheus so that Grafana will fetch the data from Prometheus. So first, add Prometheus as a data source

After click on Add Data Sources → Prometheus

Add URL of Prometheus

then click on Save & Test →Back

After Click on Dashboard

After this click on Add new Panel

run any query which is supported by Prometheus then the result is the above

then click on Save → give dashboard name

Add Multiple Panel on the dashboard

Now Delete All the Pods Of Grafana So we can check if we lost any data or not

After, you will see your dashboard is saved and the other data is also consistent like username password and other things

Thanks For Reading

Subscribe to FAUN topics and get your weekly curated email of the must-read tech stories, news, and tutorials 🗞️

Follow us on Twitter 🐦 and Facebook 👥 and Instagram 📷 and join our Facebook and Linkedin Groups 💬

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--