Integrated Prometheus and Grafana using Kubernetes
Task-5
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
Description :
Prometheus is a free software application used for event monitoring and alerting. It records real-time metrics in a time series database.
Grafana is an open-source platform for data visualization, monitoring and analysis tool.
Let's start to create yaml file to do this task
ConfigMap for Prometheus
- ConfigMap is similar to Secrets
apiVersion: v1 kind: ConfigMap metadata: name: config-pro data: prometheus.yml: |- global: scrape_interval: 10s evaluation_interval: 10s scrape_configs: - job_name: 'kubernetes' static_configs: - targets: ['localhost:9090']
Service for Prometheus
- Service is responsible for enabling network access to a set a pods.
- Here pod will run on 9090 and service is running on port 30000
apiVersion: v1 kind: Service metadata: name: prometheus labels: app: prometheus spec: ports: - port: 9090 nodePort: 30000 selector: app: prometheus tier: backend type: NodePort
Persistent Volume for Prometheus
- The data where volume is mounted will remain even after the pod is deleted.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: prometheus-storage labels: app: prometheus spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
Deployment for Prometheus
- Deployment is responsible for keeping a set of pod running
- Url https://<minikube ip>:30000
apiVersion: apps/v1 kind: Deployment metadata: name: prometheus spec: replicas: 1 selector: matchLabels: app: prometheus tier: backend strategy: type: Recreate template: metadata: labels: app: prometheus tier: backend spec: containers: - name: prometheus image: prom/prometheus volumeMounts: - name: pro-volume mountPath: /etc/prometheus - name: all-info mountPath: /prometheus ports: - containerPort: 80 securityContext: runAsUser: 0 volumes: - name: pro-volume configMap: name: config-pro - name: all-info persistentVolumeClaim: claimName: prometheus-storage
Prometheus web UI
Service for Grafana
apiVersion: v1 kind: Service metadata: name: grafana labels: app: grafana spec: ports: - port: 3000 nodePort: 30001 selector: app: grafana
type: NodePort
Persistent Volume for Grafana
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: grafana-storage labels: app: grafana spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
Deployment for Grafana
Url https://<minikube ip>:30001
apiVersion: v1
kind: Deployment metadata: name: grafana labels: app: grafana tier: frontend spec: selector: matchLabels: app: grafana tier: frontend strategy: type: Recreate template: metadata: labels: app: grafana tier: frontend spec: containers: - image: grafana/grafana:latest name: grafana ports: - containerPort: 3000 name: grafana volumeMounts: - name: all-info mountPath: /var/lib/grafana volumes: - name: all-info persistentVolumeClaim: claimName: grafana-storage
Grafana web UI
Login page
- username and password both are admin by default
- To connect to prometheus give url of it
Successfully we had deployed Prometheus and Grafana on the top of Kubernetes.
For any queries, suggestions and feedback feel free to contact me.