Integration of prometheus and grafana with kubernetes

Real Time Monitoring with Prometheus and Grafana

Samkit Shah
4 min readJun 17, 2020

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 . Prometheus collects metrics from monitored targets by scraping metrics from HTTP endpoints on these targets. But what about monitoring Prometheus itself?

Like any server running processes on a host machine, there are specific metrics that need to be monitored such as used memory and storage as well as general ones reporting on the status of the service. Conveniently, Prometheus exposes a wide variety of metrics that can be easily monitored. By adding Grafana as a visualization layer, we can easily set up a monitoring stack for our monitoring stack.

What is Prometheus ?

Prometheus is an open-source systems monitoring and alerting toolkit and it records real-time metrics in a time series database.

What is Grafana?

Grafana is a multi platform open source analytics and interactive visualization web appliccation. It provides charts, graphs, and alerts for the web when connected to supported data sources.

What is kubernetes?

Kubernetes is an open-source container-orchestration system for automating application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation

What are we gonna do?

I’ve created docker images of prometheus and grafana using Dockerfile ,which are available in my docker repository :

Links : Grafana , Prometheus

I’ve created deployment of Prometheus container but before that I’ve created Persisten Volume so that we dont loose our data

Persisten Volume for Prometheus:

Persistent Volume Claim for Prometheus:

By these command we can create pv and pvc

kubectl create -f prompv.yml

kubectl create -f prompvc.yml

Now to create a deployment for Prometheus:

To create a deployment :

kubectl create -f promdeploy.yml

After creating deployment we have to expose it to outer world using command :

kubectl expose deployment promdeploy --port=9090 --type=NodePort

Grafana

Now same process we have to follow for grafana.

Persisten Volume for Grafana:

Persisten Volume Claim for Grafana:

By these command we can create pv and pvc.

kubectl create -f grafpv.yml

kubectl create -f grafpvc.yml

Finally we can see prometheus and grafana pv and pvc

Deployment for Grafana:

To create a deployment :

kubectl create -f grafdepoy.yml

To expose it to outer world:

kubectl expose deployment grafdepoy --port=3000 --type=NodePort

Finally prometheus and Grafana both deployed and exposed :

Now using IP address of you local system k8s and using port number mentioned above we can access prometheus and grafna GUI .
Using PromQL query language in prometheus we can monitor metrics and integrated prometheus with grafana for better visuals and monitoring.

Finally real-time monitoring in Grafana

Refreshes in every 5 seconds

Lets connect on LinkedIn : LinkedIn

My GitHub : GitHub

Thanks !

--

--

Samkit Shah

Machine Learning | Deep Learning | DevOps | MLOps | Cloud Computing | BigData