Integrate Prometheus, Grafana & K8s

Problem Statement=>

Integrate Prometheus, Grafana & K8s then perform in following tasks:

Solution=>

first see about tools needed or use of it

Prometheus=>

Prometheus is a free software application used for event monitoring and alerting.It records real-time metrics in a time series database built using a HTTP pull model, with flexible queries and real-time alerting. The project is written in Go and licensed under the Apache 2 License, with source code available on GitHub,[5] and is a graduated project of the Cloud Native Computing Foundation, along with Kubernetes and Envo

Grafana=>

Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources. It is expandable through a plug-in system. End users can create complex monitoring dashboardsusing interactive query builders.
As a visualization tool, Grafana is a popular component in monitoring stacks,often used in combination with time series databases such as InfluxDB, Prometheus and Graphite; monitoring platforms such as Sensu,Icinga, Zabbix, Netdata, and PRTG; SIEMs such as Elasticsearch and Splunk; and other data sources.

Kubernetes=>

Kubernetes (commonly stylized as K8s) is an open-source container-orchestration system for automating computer application deployment, scaling, and management.
It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation. It aims to provide a “platform for automating deployment, scaling, and operations of application containers across clusters of hosts”. It works with a range of container tools, including Docker.
Many cloud services offer a Kubernetes-based platform or infrastructure as a service (PaaS or IaaS) on which Kubernetes can be deployed as a platform-providing service. Many vendors also provide their own branded Kubernetes distributions.

Docker=>

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines.
The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. It was first started in 2013 and is developed by Docker, Inc.

we create Dockerfile of prometheus

FROM centos:8
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 -xvf prometheus-2.19.0.linux-amd64.tar.gz
WORKDIR prometheus-2.19.0.linux-amd64/
EXPOSE 9090
CMD ./prometheus

Now We create a Docker file of Grafana

FROM centos:8
RUN yum install wget -y
RUN wget https://dl.grafana.com/oss/release/grafana-7.0.3.linux-amd64.tar.gz
RUN tar -zxvf grafana-7.0.3.linux-amd64.tar.gz
WORKDIR grafana-7.0.3/bin/
EXPOSE 3000
CMD ./grafana-serve
apiVersion: v1
kind: Service
metadata:
name: promo-service
labels:
env: prometheus
spec:
ports:
- port: 9090
selector:
env: prometheus
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: prometheuspvc
labels:
env: prometheus
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: promo-deployment
labels:
env: prometheus
spec:
selector:
matchLabels:
env: prometheus
strategy:
type: Recreate
template:
metadata:
labels:
env: prometheus
spec:
containers:
- image: vimal13/prometheus:latest
name: prometheus
ports:
- containerPort: 9090
name: prometheus
volumeMounts:
- name: prometheus-mount
mountPath: /etc/prometheus/data
volumes:
- name: prometheus-mount
persistentVolumeClaim:
claimName: prometheuspvc

now promotheus run Successfully 😎😎👆👆🤘🤘

now we create one more yml file for Grafana

apiVersion: v1
kind: Service
metadata:
name: grafana-svc
labels:
env: grafana
spec:
ports:
- port: 3000
selector:
env: grafana
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: grafana-pvc
labels:
env: grafana
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana-deployment
labels:
env: grafana
spec:
selector:
matchLabels:
env: grafana
strategy:
type: Recreate
template:
metadata:
labels:
env: grafana
spec:
containers:
- image: princeprashantsaini/grafana:v1
name: grafana
ports:
- containerPort: 3000
name: grafana
volumeMounts:
- name: grafana-volume
mountPath: /var/lib/grafana
volumes:
- name: grafana-volume
persistentVolumeClaim:
claimName: grafana-pvc
now work successfully done 😎😎🤘🤘✔

Now check its volume is permanent or not for this check our PVC

🙏🙏Now all Task done Thanks for reading🙏🙏

Devops Engineer