Articles in this section
Category / Section

How to Monitor and Alert Bold Reports Using Grafana and Prometheus in Kubernetes

Published:
Updated:

This guide provides the steps to configure Grafana and Prometheus in a Kubernetes cluster. Monitoring the performance of your Kubernetes cluster is crucial for maintaining the health and efficiency of your applications. By connecting to the Kubernetes cluster you want to monitor, and setting up Grafana and Prometheus, you will be able to collect, visualize, and analyze performance metrics in real-time. This setup will enable you to effectively monitor, troubleshoot, and optimize your Kubernetes environment.

Configure Grafana and Prometheus:

Follow these steps to configure Grafana and Prometheus in the Kubernetes cluster:

  1. Connect to the Kubernetes cluster that you want to monitor.

  2. If Helm is not installed on your machine, you can install it using Chocolatey with 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'))
    
  3. Add the Prometheus Helm repository 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
    
  4. Update the Helm repository.

    helm repo update
    
  5. Add the Prometheus community Helm chart to Kubernetes.

    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    
  6. After running the above command to add the Prometheus and Grafana Helm charts, proceed to install the kube-prometheus-stack.

  7. Install the stable Prometheus-community/kube-prometheus-stack.

    helm install stable prometheus-community/kube-prometheus-stack
    
  8. Once installed, you will see the following output:

    output.png

    kubectl get pods
    

    prometheus-running-state.png

Edit Grafana and Prometheus services for external access:
  1. By default, the Prometheus and Grafana services are available within the cluster using ClusterIP. To access them externally, change the service type to either NodePort or LoadBalancer.

    kubectl edit svc stable-kube-prometheus-sta-prometheus
    
  2. Change the service type from ClusterIP to LoadBalancer or NodePort.

    type-load-balancer.png

  3. Edit the Grafana service in the same way as you did for Prometheus.

  4. Run the command below to get the services.

    Kubectl get svc
    
  5. The LoadBalancer assigns an external IP to both the Grafana and Prometheus services.

    assign-external-ip.png

  6. Access Grafana and Prometheus using the provided IP address and port.

    access-grafana-prometheus.png

    grafana-welcome-page.png

  7. Add this Prometheus as a data source in Grafana.

    prometheus-as-datasource.png

  8. Click Add data source.

    click-add-datasource.png

  9. Search for Prometheus and enter the external IP address and port number of your Prometheus service in the URL field.

    prometheus-external-ip.png

  10. Then, click Save & Test.

    click-save-test.png

  11. The data source is now configured in Grafana.

Dashboard Creation and Monitoring:
  1. Grafana has a default dashboard for monitoring cluster performance.

  2. Use the following Grafana dashboard ID for overall cluster monitoring.

    dashboard-page.png

  3. Use the dashboard ID - 9873 and select Prometheus as the data source for the dashboard creation.

    dashboard-creation-page.png

  4. Refer here for more dashboards.

Configure Alerting:
  1. Add a notification channel to receive alerts.

    add-notification-channel.png

  2. Enter your email address and click Save Contact Point.

    click-save-contact-point.png

  3. Refer here for instructions on configuring SMTP in Grafana to receive emails.

  4. Save and test the contact point.

  5. Refer here for instructions on creating alerts in Grafana.

  6. For example, to create a “Pods Down” alert rule, go to the Alerts section and click Add New Alert.

    click-new-alert-rule.png

  7. Search for a PromQL query(Prometheus Query Language) to find pods in your namespace.

    promsql.png

  8. Set the threshold to 1 and add the other details.

    summary-annotations.png

  9. Click Save.

    click-save-and-exit.png

  10. Find your alert rule under Alert Rules.

    alert-rule.png

  11. After creating the alert in Grafana, it will send an email notification to the specified address (e.g., Gmail) when the alert is triggered.

    alert-email.png

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied