Launching Prometheus and Grafana on Kubernetes with NFS as Persistent Volume

Objective

Launch Prometheus and Grafana as Kubernetes Pods, respective data should remain persistent and both the pods should be exposed to outside world.

Content of this Blog

  • Project Understanding : Prometheus
  • Project Understanding : Grafana
  • Project Understanding : Kubernetes
  • Output

Project Understanding : Prometheus

Prometheus is an open-source event monitoring and alerting tool.”

Dockerfile used to create the image is mentioned below:

Dockerfile mentioned above provides Prometheus setup, adds the custom prometheus.yml, launches Prometheus when container is created from the same and exposes the respective port number.

The target node is updated in prometheus.yml file and is copied to the container in the specified directory. It is mentioned in the Dockerfile used to create the image for respective container creation.

  • Node exporter needs to be setup in the target host server to obtain their metrics respectively. The guide to set up the same for Linux could be obtained here. The target host is mentioned under static_configs in prometheus.yml above.
  • Both Dockerfile and prometheus.yml should be in same directory.

Project Understanding : Grafana

Grafana is the open source analytics & monitoring solution for every database.”

Dockerfile used to create the image is mentioned below:

Dockerfile mentioned above provides Grafana setup, launches Grafana when container is created from the same and exposes the respective port number.

  • Image needs to be built from Dockerfile and then pushed to Docker Hub by logging into respective account and then pushing it in the required format.
  • Commands for building image and pushing image is as follows

username here refers to Docker Hub username and password refers to Docker Hub password.

Project Understanding : Kubernetes

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation.”

Creates NFS as Persistent Volume and Persistent Volume Claim to retrieve memory from NFS as per requirement for Prometheus.

Creates Deployment for Prometheus and exposes it using NodePort. Mount path specified is ./data directory that stores the respective data and is mounted to directory i.e., prometheus(mentioned in prometheus-pv.yaml) in NFS server.

Creates NFS as Persistent Volume and Persistent Volume Claim to retrieve memory from NFS as per requirement for Grafana.

Creates Deployment for Grafana and exposes it using NodePort. Mount path specified is /var/lib/grafana directory that stores the respective data and is mounted to directory i.e., grafana(mentioned in grafana-pv.yaml) in NFS server.

Kustomize is used for setting up management for Kubernetes Objects like Volume, Pods, Deployments and many more

In this case, a RHEL 8 VM(Virtual Machine) was used as NFS server. The steps to set up the same is as follows:

  • Install NFS Server using package management tool(in this case, it’s YUM). The command using YUM is as follows:
  • Enable the service respective to NFS server using the command mentioned below:
  • Create the directory to store data in a persistent manner.
  • Edit the /etc/exports file and add entries in the format as mentioned below:

<path_to_directory> is mentioned under PersistentVolume kind for both Prometheus and Grafana.

  • Restart the service respective to NFS server to apply the changes in /etc/exports file.
  • The command used to execute kustomization.yaml is
  • Deployments, Service, PV & PVC were created in a single node cluster that could be obtained by downloading minikube and client-side CLI tool like kubectl.

Output

Prometheus Target Lists(Click on Status on top left and then go for Targets)
PromQL Query Execution
Addition of Prometheus Data Source by mentioning Prometheus’s IP Address
Click on ‘Add Panel’ icon on right hand side and then click on ‘Add an empty panel’
Add the PromQL query, select the graph type and mention the title
Grafana Dashboard
Persistent Storage for Prometheus Data
Persistent Storage for Grafana Data

--

--

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