Setup Prometheus and Grafana On Kubernetes And Make Persistent Using ConfigMap

Fault tolerance setup ready
Metrics collection

So, What is Prometheus?

Visuals

What is Grafana?

Steps Involved

Let’s Go

Step 1:

Minikube start
kubectl create deployment (name) --image=vimal13/prometheus
kubectl create deployment (name) --image=vimal13/grafana
kubectl expose deployment (deploymentname) --type=NodePort --port=9090kubectl expose deployment (deploymentname) --type=NodePort --port=3000
Prometheus
Grafana

Step 2:

exporter
tar -xzf node_exporter-1.0.0.linux-amd64.tar.gz
nohup ./node_exporter &
Start Agent
Configure

Step 3:

why???

But why???

apiVersion: v1
kind: ConfigMap
metadata:
name: prom-graf-config
data:
prometheus.yml: |-
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'RHEL8'
static_configs:
- targets: ['192.168.43.197:9100']

datasource.yml: |-
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://192.168.99.100:30002
apiVersion: v1
kind: Service
metadata:
name: prometheus
labels:
app: prometheus
spec:
ports:
- port: 9090
nodePort: 30002
selector:
app: prometheus
type: NodePort
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-prometheus
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: prom-deploy
labels:
app: prometheus
spec:
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
containers:
- image: prom/prometheus
name: prometheus
ports:
- containerPort: 9090
name: prometheus
volumeMounts:
- name: prom-config
mountPath: /etc/prometheus/prometheus.yml
subPath: prometheus.yml
- name: pv-prometheus
mountPath: /prometheus
volumes:
- name: prom-config
configMap:
name: prom-graf-config
- name: pv-prometheus
persistentVolumeClaim:
claimName: pvc-prometheus
apiVersion: v1
kind: Service
metadata:
name: grafana
labels:
app: grafana
spec:
ports:
- port: 3000
nodePort: 30003
selector:
app: grafana
type: NodePort
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-grafana
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: graf-deploy
labels:
app: grafana
spec:
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
containers:
- image: grafana/grafana
name: grafana
ports:
- containerPort: 3000
name: grafana
volumeMounts:
- name: graf-config
mountPath: /etc/grafana/provisioning/datasources/datasource.yml
subPath: datasource.yml
- name: pv-grafana
mountPath: /var/lib/grafana
volumes:
- name: graf-config
configMap:
name: prom-graf-config
- name: pv-grafana
persistentVolumeClaim:
claimName: pvc-grafana
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- configmap.yml
- Prometheus.yml
- Grafana.yml
kubectl create -k .
Setup ready
confirmation of setup
Output
Output
Output

Mlops, DevOps Assembly lines, Hybrid Multi cloud, Flutter, Ansible and many more...

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store