DevOps: Monitoring Tools (Prometheus and Grafana)

  • Continuous Monitoring is the process of monitoring each and every phase of DevOps and IT operations lifecycle. This process ensures the health, performance, and reliability of your application.
  • Prometheus and Grafana are two open-source tools used for monitoring the applications. Prometheus stored the metrics at backend and Grafana visualize those metrics.

TASK :

Prometheus:

Dockerfile:

FROM centos:latest


RUN yum install wget -y

RUN wget https://github.com/prometheus/prometheus/releases/download/v2.19.0/prometheus-2.19.0.linux-amd64.tar.gz

RUN tar -xzf prometheus-2.19.0.linux-amd64.tar.gz

RUN mkdir /logs

CMD ./prometheus-2.19.0.linux-amd64/prometheus --config.file=/prometheus-2.19.0.linux-amd64/prometheus.yml --storage.tsdb.path=/logs && tail -f /dev/null
docker build -t skabhi003/prometheus:latest .

Creating Persistent volume:

  • I am creating persistent volume for prometheus to store prometheus data .
apiVersion: v1kind: PersistentVolumemetadata:
name: prometheus-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/sda1/data/prometheus"

PersistentVolumeClaim:

apiVersion: v1kind: PersistentVolumeClaimmetadata:
name: prometheus-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

Prometheus-deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-deployment
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
template:
metadata:
name: prometheus-deployment
labels:
app: prometheus
spec:
volumes:
- name: prometheus-storage
persistentVolumeClaim:
claimName: prometheus-pvc

containers:
- name: prometheus-os
image: skabhi003/prometheus:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/logs"
name: prometheus-storage

Grafana:

Dockerfile:

FROM centos


RUN yum install wget -y

RUN wget https://dl.grafana.com/oss/release/grafana-7.0.3-1.x86_64.rpm

RUN yum install grafana-7.0.3-1.x86_64.rpm -y


WORKDIR /usr/share/grafana


CMD /usr/sbin/grafana-server start && /usr/sbin/grafana-server enable && /bin/bash
docker build -t skabhi003/grafana:latest .

PersistentVolume:

apiVersion: v1kind: PersistentVolumemetadata:
name: grafana-pv
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/sda1/data/grafana"

PersistentVolumeClaim:

apiVersion: v1kind: PersistentVolumeClaimmetadata:
name: grafana-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

Grafana-deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana-deployment
spec:
selector:
matchLabels:
app: grafana
template:
metadata:
name: grafana-deployment
labels:
app: grafana

spec:
volumes:
- name: grafana-storage
persistentVolumeClaim:
claimName: grafana-pvc
containers:
- name: grafana-os
image: skabhi003/grafana:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/var/lib/grafana"
name: grafana-storage
restartPolicy: Always

Kustomization:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- grafa-pv.yml
- prome-pv.yml
- grafa-pvc.yml
- prome-pvc.yml
- prome-deploy.yml
- grafa-deploy.yml
kubectl create -k .
kubectl expose deployment prometheus-deployment --port=9090 --type=NodePortkubectl expose deployment grafana-deployment --port=3000 --type=NodePort

Monitoring:

  • Use the IP address of the Kubernetes Node along with the Port number generated for the Prometheus Deployment.

Githhub link:

https://github.com/skabhi001/dev-task5

Thanks, hope you guys will like my article. if you have any suggestion or query will free to ask.

#Happylearning #keepsharing #devops #integration

--

--

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