Major_Task

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

(Major Project)

Deploy Prometheus and Grafana on Kubernetes.


Name: Rudraksh Wagh Date: 13/7/24
Task: Deploy Prometheus and Grafana on Kubernetes.

Scenario: This task requires you deploying Prometheus and Grafana on


a Kubernetes cluster to monitor cluster health and application metrics.
Your team requires monitoring capabilities for your Kubernetes cluster.
This task focuses on deploying Prometheus and Grafana to collect and
visualize application and infrastructure metrics.
- Use Kubernetes version 1.30

Solution:
Step 1: Make sure you have kubernetes 1.30 is installed on your
machine. Check it by below command:-

 kubectl get nodes


Step 2: Create a namespace called „monitoring‟ for deploying
Prometheus, grafana in it & git clone the Prometheus files into system:-

 kubectl create namespace monitoring


 git clone https://github.com/bibinwilson/kubernetes-prometheus
 cd kubernetes-prometheus

Here you can see all the Prometheus files have been downloaded:-

 prometheus-deployment.yaml
 prometheus-service.yaml
 prometheus-ingress.yaml
 clusterRole.yaml
 config-map.yaml
Step 3: Create all files in the directory by following this command:-

 kubectl create –f .
 kubectl get all –n monitoring (to see all objects in that namespace)

Step 4: Create a yaml file for Grafana including all the objects in it:-
vi grafana (enter the below code & save the file):-
---------------------------------------------------------------------------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-datasources
namespace: monitoring
data:
prometheus.yaml: |-
{
"apiVersion": 1,
"datasources": [
{
"access":"proxy",
"editable": true,
"name": "prometheus",
"orgId": 1,
"type": "prometheus",
"url": "http://prometheus-service.monitoring.svc:8080",
"version": 1
}
]
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
name: grafana
labels:
app: grafana
spec:
containers:
- name: grafana
image: grafana/grafana:latest
ports:
- name: grafana
containerPort: 3000
resources:
limits:
memory: "2Gi"
cpu: "1000m"
requests:
memory: "1Gi"
cpu: "500m"
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-storage
- mountPath: /etc/grafana/provisioning/datasources
name: grafana-datasources
readOnly: false
volumes:
- name: grafana-storage
emptyDir: {}
- name: grafana-datasources
configMap:
defaultMode: 420
name: grafana-datasources
---
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: monitoring
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '3000'
spec:
selector:
app: grafana
type: NodePort
ports:
- port: 3000
targetPort: 3000
nodePort: 32000
---------------------------------------------------------------------------------------
Then apply the code by,

 kubectl create –f grafana.yml


 kubectl get pods –n monitoring (to see pods)
 kubectl get svc –n monitoring( to see services)
Step 5: Check the service on your browser:-
Open your browser & type http://localhost:32000 (port number of
grafana service). For the first time you have to login. The default
username & password is “admin” for both, then also you can change
your password.
Step 6: After deploying Grafana you will get this below screen, „import
dashboard‟. Now you can add your own visualization or import any
dashboard by using ID of the dashboard and “Click on Load “ then click
on data source & select Prometheus as data source:-
Here you can see the cluster monitoring & changes in the Cluster
memory usage, Cluster CPU usage, etc in the below screen:-
Also, this is the Application monitoring of the cluster:-

You might also like