Deploying Prometheus and Grafana over Kubernetes

Deploying Prometheus and Grafana over Kubernetes

Task:

  • Creating Docker images for Prometheus & Grafana.
  • Deploying Prometheus & Grafana as pods on top of Kubernetes by creating resources Deployment, ReplicaSet, Pods or Services.
  • Making their data persistent using PVC. 
  • Exposing both pods to Outside world

Creating Docker images for Prometheus & Grafana

Grafana

FROM centos:latest
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

I created grafana image on top of centos using Dockerfile and uploaded the image to DockerHub, so that we can directly download the image from there.

No alt text provided for this image

Prometheus

Lets do the same for Prometheus image

FROM centos


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 /prom_data

CMD ./prometheus-2.19.0.linux-amd64/prometheus --config.file=/prometheus-2.19.0.linux-amd64/prometheus.yml --storage.tsdb.path=/prom_data && tail -f /dev/null
No alt text provided for this image

Creating Deployment

Prometheus

apiVersion: apps/v1
kind: Deployment
metadata:
  name: prom-deploy
  labels:
    app: prometheus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      name: prom-deploy
      labels:
        app: prometheus
    spec:
      volumes:
        - name: prom-pv-vol
          persistentVolumeClaim:
            claimName: prom-pv-volclaim
        
      containers:
        - name: prometheus
          image: gauravmehta13/prometheus:v2
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9090
          volumeMounts:
            - mountPath: "/metrics"
              name: prom-pv-vol

Grafana

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana
  labels:
    app: grafana
spec:
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      name: grafana
      labels:
        app: grafana
    
    spec:
      containers:
        - name: grafana
          image: gauravmehta13/grafana:v1
      imagePullPolicy: IfNotPresent

      restartPolicy: Always

PVC

apiVersion: v1


kind: PersistentVolumeClaim


metadata:
  name: prom-pv-volclaim


spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

Kustomization

I used Kustomization to run all the yml files in a sequence.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - pvc.yml
  - prometheus.yml
  - grafana.yml

We have to use kubectl create -k . for running kustomization file

No alt text provided for this image

Let's check the running pods

No alt text provided for this image

Now, we have to expose these pods using type NodePort

#For exposing to outside world
kubectl expose deployment grafana --port=3000 --type=NodePort
kubectl expose deployment prom-deploy --port=9090 --type=NodePort

After this we can check the ports using kubectl get svc

No alt text provided for this image

Configuring Grafana

  • The default username and password are admin
  • After that we will get a screen to change password
No alt text provided for this image
No alt text provided for this image
  • Now, We have to go to Data Source and select Prometheus and provide its url.
No alt text provided for this image

Now, We are ready to Monitor

We can can now view the real-time Metrics information visuals through Grafana using PromQl. We also have created Persistent storage so that even if the Pods crash due to some reason, Prometheus will automatically retrieve the data back.

No alt text provided for this image



要查看或添加评论,请登录

Gaurav Yadav的更多文章

  • Hosting Wordpress on AWS with maximum Security

    Hosting Wordpress on AWS with maximum Security

    Task Write a Infrastructure as code using terraform, which automatically create a VPC. In that VPC we have to create 2…

    2 条评论
  • Jenkins Automation Using Groovy

    Jenkins Automation Using Groovy

    In this tutorial I tried to Show how to use Groovy script to build a Jenkins pipeline. Groovy is suitable for beginners…

    1 条评论
  • Setting Up WordPress On AWS Using Amazon EKS

    Setting Up WordPress On AWS Using Amazon EKS

    Tasks: Kubernetes Cluster using AWS EKS. Integrate EKS with EC2,EBS,LB,EFS.

  • Deploying Openstack on AWS

    Deploying Openstack on AWS

    Probably everyone with OpenStack hands-on experience would agree that sometimes it could be hard and frustrating to…

    3 条评论
  • Kubernetes deployment and Monitoring using Jenkins

    Kubernetes deployment and Monitoring using Jenkins

    Task: Using Jenkins Server on Rhel, Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in…

    1 条评论
  • Number Plate Detection With Supervise.ly

    Number Plate Detection With Supervise.ly

    What is Supervisely? There are many open-sourced implementations of state of the art neural network architectures. But…

    8 条评论
  • Infrastructure as Code with AWS and Terraform

    Infrastructure as Code with AWS and Terraform

    For This Task, I first created an Amazon Machine Image(AMI) from an instance in which I configured Jenkins and Apache…

    20 条评论
  • CI/CD Pipeline Using Kubernetes

    CI/CD Pipeline Using Kubernetes

    Task Description 1. Create container image that’s has Linux and other basic configuration required to run Slave for…

    4 条评论
  • Hyperparameter Tuning using MLOps

    Hyperparameter Tuning using MLOps

    The percentage of AI models created but never put into production in large enterprises has been estimated to be as much…

    2 条评论
  • Facial Recognition using Transfer Learning

    Facial Recognition using Transfer Learning

    Transfer learning is a machine learning method where a model developed for a task is reused as the starting point for a…

    1 条评论

社区洞察

其他会员也浏览了