How to Monitor and Alert Bold BI Using Grafana and Prometheus in Kubernetes
Configure Grafana and Prometheus:
Follow these steps to configure Grafana and Prometheus in the Kubernetes cluster.
- Connect the Kubernetes cluster which you want to monitor.
- Install helm using Chocolatey if you do not have it on your machine using the following command.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((NewObjectSystem.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- Add the Prometheus helm repo using the following command.
helm repo add stable https://charts.helm.sh/stable helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- Update the helm repo.
helm repo update
- Add the Prometheus community helm chart in Kubernetes.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- After running the above command Prometheus and Grafana helm chart, move to the kube Prometheus stack.
- Install stable Prometheus-community/kube-Prometheus-stack.
helm install stable prometheus-community/kube-prometheus-stack
- Once installed, you will see the following output.
kubectl get pods
Edit Grafana and Prometheus services for external access:
-
By default, Prometheus and Grafana service is available within the cluster using ClusterIP. To access it outside, change it to either NodePort or Loadbalancer.
kubectl edit svc stable-kube-prometheus-sta-prometheus
-
Here, change from ClusterIP to LoadBalancer/NodePort.
-
Edit the Grafana service as same as you did for Prometheus.
-
Run the below command to get services.
Kubectl get svc
-
Load Balancer assigned an External IP to both Grafana and Prometheus services.
-
Access Grafana and Prometheus with the mentioned** IP address and port**.
-
Add this Prometheus as a data source in Grafana.
-
Click Add a data source.
-
Search Prometheus and give your Prometheus service external Ip with the port number in the URL.
-
Then click Save and Test.
-
Now, Data Source is configured in Grafana.
Dashboard Creation and Monitoring:
-
Grafana has a default dashboard for monitoring our cluster performance.
-
Use the following Grafana dashboard ID for overall cluster monitoring.
-
Use this dashboard ID – 9873 and select Prometheus as a data source for dashboard creation.
-
Refer to here for more dashboards.
Configure Alerting:
-
Add a notification channel for receiving alerting.
-
Enter your email and click save contact point.
-
Refer to here for configuring SMTP for Grafana for receiving mail.
-
Save and test the contact point
-
Refer to here for creating an alert in Grafana.
-
For example, now we are creating pods down the alert rule, go to alert, and click add a new alert.
-
Search a prom SQL query for finding pods in our namespace.
-
Set the threshold equal to 1 and add the other details.
-
Click save.
-
Find your alert rule under alert rules.
-
After creating the alert in Grafana, It will send the alert mail after it is triggered to mention Gmail as follows.