Setting Up Prometheus and Grafana on a Kubernetes Cluster - beginners

Introduction
This guide provides a step-by-step approach to installing and configuring Prometheus and Grafana on a Kubernetes cluster using Helm charts.
What is Helm?
Helm is a package manager for Kubernetes that simplifies the process of deploying, configuring, and managing applications and services on a Kubernetes cluster. It uses a packaging format called charts, which are collections of files that describe a related set of Kubernetes resources.
What is Prometheus?
Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability. It collects and stores metrics as time series data, providing powerful querying capabilities and flexible alerting options.
What is Grafana?
Grafana is an open-source platform for monitoring and observability. It allows you to query, visualize, and alert on metrics from various data sources, including Prometheus. Grafana provides a rich set of dashboards and graphing options to help you make sense of your metrics data.
Prerequisites
- A running Kubernetes cluster
- Helm installed on your local machine
Step-by-Step Installation Guide
1. Add Helm Repositories
First, add the Helm repositories for Prometheus and Grafana.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
2. Install Prometheus
Install Prometheus using the Helm chart from the prometheus-community repository.
helm install my-prometheus prometheus-community/prometheus
3. Install Grafana
Install Grafana using the Helm chart from the grafana repository.
helm install my-grafana grafana/grafana
4. Retrieve Grafana Admin Password
To log in to the Grafana dashboard, you'll need the admin password. Retrieve it using the following command:
kubectl get secret --namespace default my-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
5. Port Forward Grafana Service
Port forward the Grafana service to make it accessible from your local machine.
kubectl port-forward service/my-grafana 3000:80 --address='0.0.0.0'
6. Access Grafana Dashboard
Open your browser and navigate to http://localhost:3000. Log in using the username admin and the password you retrieved in step 4.
7. Add Prometheus as a Data Source in Grafana
In the Grafana dashboard, go to Configuration > Data Sources.
Click Add data source.
Select Prometheus.
In the HTTP section, set the URL to
http://my-prometheus-server.Click Save & Test to ensure the connection is successful.
8. Import Kubernetes Dashboard
In the Grafana dashboard, go to Create > Import.
Enter the ID of the dashboard you want to import (e.g., 315 for Kubernetes cluster monitoring).
Click Load.
Select Prometheus as the data source and click Import.
Conclusion
You have successfully installed Prometheus and Grafana on your Kubernetes cluster, added Prometheus as a data source in Grafana, and imported a Kubernetes monitoring dashboard.
For more detailed configurations and customizations, refer to the official Prometheus Helm Chart documentation and Grafana Helm Chart documentation.


