https://www.jenkins.io

Integration of Prometheus & Grafana on K8s deployed using Jenkins Dynamic Slaves.

Prerequisites:-

Solutions:-

Create two Jenkins Job to complete this task as follows:-

echo "prometheus tasks are started"
if kubectl get cm prometheus-config-file-volume
then
echo "config map already created and applying the latest changes"
kubectl create configmap prometheus-config-file-volume --from-file=/storage/prometheus.yml -o yaml --dry-run=client | kubectl replace -f -
else
kubectl create configmap prometheus-config-file-volume --from-file=/storage/prometheus.yml
echo "config map created for premetheus config file"
fi
if kubectl get svc prometheus-svc
then
echo "prometheus service is already created and applying latest changes"
kubectl apply -f /storage/prometheus-svc.yml
else
kubectl apply -f /storage/prometheus-svc.yml
echo "creating prometheus service"
fi
if kubectl get pvc prometheus-storage-pvc
then
echo "prometheus pvc is already created and applying latest changes"
kubectl apply -f /storage/prometheus-pvc.yml
else
kubectl apply -f /storage/prometheus-pvc.yml
echo "creating prometheus pvc"
fi
if kubectl get deploy prometheus-deployment
then
echo "prometheus deployment is already created and applying latest changes"
kubectl apply -f /storage/prometheus-deployment.yml
else
kubectl apply -f /storage/prometheus-deployment.yml
echo "creating prometheus deployment"
fi
echo "prometheus tasks are ended"echo "grafana tasks are started"if kubectl get svc grafana-svc
then
echo "grafana-svc is already created and applying latest changes"
kubectl apply -f /storage/grafana-svc.yml
else
kubectl apply -f /storage/grafana-svc.yml
echo "creating grafana-svc service"
fi
if kubectl get pvc grafana-storage-pvc
then
echo "grafana-storage-pvc is already created and applying latest changes"
kubectl apply -f /storage/grafana-pvc.yml
else
kubectl apply -f /storage/grafana-pvc.yml
echo "creating grafana-storage-pvc"
fi
if kubectl get deploy grafana-deployment
then
echo "grafana-deployment is already created and applying latest changes"
kubectl apply -f /storage/grafana-deployment.yml
else
kubectl apply -f /storage/grafana-deployment.yml
echo "creating grafana-deployment"
fi
echo "grafana tasks are ended"

Now we can access our Prometheus services and Grafana services.

[root@server ~]# ls /storage/
default-grafana-storage-pvc-pvc-0ccdd2d9-6008-4947-a895-b7d9d359e475
default-prometheus-storage-pvc-pvc-125fb35e-f5a8-4d58-b2e1-bc445dcbcd12
[root@server ~]# ls /storage/default-prometheus-storage-pvc-pvc-125fb35e-f5a8-4d58-b2e1-bc445dcbcd12/
chunks_head lock queries.active wal
[root@server ~]# ls /storage/default-grafana-storage-pvc-pvc-0ccdd2d9-6008-4947-a895-b7d9d359e475/
grafana.db plugins png

I'm a computer science undergraduate and my primary area of work is under Linux, CloudComputing, DevOps culture, and various open-source tools and technologies

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