- DevOps includes software development and IT operations. Its main aim is to automate the systems deployment life cycle and provide continuous delivery without the downtime and with high software quality.
- 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 :
→ Deploying Prometheus and Grafana as a pod on Kubernetes by creating resources Deployment, PV ,PVC and service.
Prometheus:
- I am going to create my own docker image of prometheus by using Dockerfile.
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
- Build the above Docker image from the following command:
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: localspec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/sda1/data/prometheus"
PersistentVolumeClaim:
apiVersion: v1kind: PersistentVolumeClaimmetadata:
name: prometheus-pvcspec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Prometheus-deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-deploymentspec:
replicas: 1
selector:
matchLabels:
app: prometheustemplate:
metadata:
name: prometheus-deployment
labels:
app: prometheusspec:
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:
- Now, I am creating my own docker image of 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
- Build the above Docker image from the following command:
docker build -t skabhi003/grafana:latest .
PersistentVolume:
apiVersion: v1kind: PersistentVolumemetadata:
name: grafana-pv
labels:
type: localspec:
storageClassName: manual
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/sda1/data/grafana"
PersistentVolumeClaim:
apiVersion: v1kind: PersistentVolumeClaimmetadata:
name: grafana-pvcspec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Grafana-deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana-deploymentspec:
selector:
matchLabels:
app: grafanatemplate:
metadata:
name: grafana-deployment
labels:
app: grafana
spec:
volumes:
- name: grafana-storage
persistentVolumeClaim:
claimName: grafana-pvccontainers:
- name: grafana-os
image: skabhi003/grafana:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/var/lib/grafana"
name: grafana-storagerestartPolicy: Always
- Now I am creating a Kustomization file for running all the above files using the single command :
Kustomization:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomizationresources:
- grafa-pv.yml
- prome-pv.yml
- grafa-pvc.yml
- prome-pvc.yml
- prome-deploy.yml
- grafa-deploy.yml
- Run the above kustomization file using :
kubectl create -k .
- After creating our deployments , I am exposing it to outside world.
kubectl expose deployment prometheus-deployment --port=9090 --type=NodePortkubectl expose deployment grafana-deployment --port=3000 --type=NodePort
- Now , We can see that the containers have been deployed:
Monitoring:
- Use the IP address of the Kubernetes Node along with the Port number generated for the Prometheus Deployment.
- Similarly use the same IP with the port number for Grafana Deployment.
- We have both the tools ready for monitoring. We can can now view the real-time Metrics data by using PromQL inside the Prometheus UI and create dashboards and panels to view corresponding real-time visuals of the data through Grafana. We also have Persistent storage both for Prometheus and Grafana so that even if the Pods crash due to some reason, they will automatically retrieve the lost data.
Githhub link:
https://github.com/skabhi001/dev-task5