?? DevOps Task-5 ??
Tushar Dighe
DevOps/Cloud Engineer | Kubernetes | GCP | AWS | Azure | Wiz | Databricks| Cycode | Security
Deploy prometheus and grafana on the top of kubernetes .
Tasks :
Integrate Prometheus and Grafana and perform in following way:
1. Deploy them as pods on top of Kubernetes by creating resources Deployment, ReplicaSet, Pods or Services
2. And make their data to be remain persistent
3. And both of them should be exposed to outside world
What is 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.
It stores data locally on disk, which helps for fast data storage and fast querying. There is ability to store metrics in remote storage .It collects data in the form of time series.
Whats is 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 dashboards using 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.
Data Persistence is “the continuance of an effect after its cause is removed”. In the context of storing data in a computer system, this means that the data survives after the process with which it was created has ended. In other words, for a data store to be considered persistent, it must write to non-volatile storage.
To Integrate Prometheus and Grafana we are going to use Kubernetes …
Steps to Integrate Prometheus & Grafana
Step 1 : Create the docker images of the Grafana And Prometheus...
Docker image of Prometheus
I have download tar file of prometheus and then extract it using command
tar -xzf prometheus-2.18.1.linux-amd64.tar.gz
and in the same folder where we have promeutheus extracted file , i am going create a Dockerfile in which i have written below code for building image of prometheus.
FROM centos COPY prometheus-2.20.1.linux-amd64 / EXPOSE 9090 CMD ["./prometheus"]
now run the command to build image
docker build -t tushardighe/prometheus .
once image is created push it to docker hub using command
docker push tushardighe/prometheus
Docker image of Grafana
Similar process as we done for promtheus image , we will do for grafana too.
we will create a dockerfile that will contain code for building image of grafana
FROM centos RUN yum install wget -y RUN wget https://dl.grafana.com/oss/release/grafana-7.1.1-1.x86_64.rpm RUN yum install grafana-7.1.1-1.x86_64.rpm -y EXPOSE 3000 WORKDIR /usr/share/grafana/ CMD ["/usr/sbin/grafana-server","--config=/etc/grafana/grafana.ini"]
So then build the image and push the dockerhub using below commands
docker build -t tushardighe/grafana . docker push tushardighe/grafana
Step 2 : To make data persistent of prometheus and grafana server . Create pvc for both pods … Here is the code …
--- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: prometheus-pvc labels: name: prometheuspvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: grafana-pvc labels: name: grafanapvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi ---
Step 3 : Write the code for deploying prometheus and grafana …. And expose to world … Here I wrote deployment and service in single file …
The Deployment code & all codes is my github account so link : https://github.com/dighetushar654/DevOps_Task-5
Step 4 : For Automation purpose , I am going to write a kustomization yml code …
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - pvc.yml - deploygrafprom.yml
Now type the command “ kubectl apply -k . “ in console…
Note : Run the cmd only in the respective folder,, Means go to folder where u have created kustomization.yml , pvc.yml , deploygrafprom.yml ….
Output :
Prometheus port → 32507 ( It is a random port number )
Grafana Port → 31157( It is a random port number )
Prometheus Server
Grafana Server
Finally done with the task ….
Thanks for Reading …