Kubernetes is a powerful orchestration tool, but monitoring its performance is crucial for ensuring smooth operations. This is where Prometheus and Grafana come into play. Prometheus is a leading open-source monitoring solution, while Grafana is a visualization tool that helps make sense of the collected data.
In this guide, weβll walk through setting up Prometheus and Grafana on Minikube, a local Kubernetes cluster, to monitor and visualize cluster metrics. This tutorial is beginner-friendly and will help you get hands-on experience with Kubernetes monitoring.
Before we start, ensure you have the following installed:
- Minikube (Install Guide)
- kubectl (Install Guide)
- Helm (Install Guide)
To verify Minikube is installed, run:
minikube version
First, start your Minikube cluster:
minikube start
Check the status:
minikube status
It's a good practice to keep monitoring components in a separate namespace.
kubectl create namespace monitoring
1οΈβ£ Add the Prometheus Helm repository:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
2οΈβ£ Install Prometheus:
helm install prometheus prometheus-community/prometheus -n monitoring
3οΈβ£ Verify the installation:
kubectl get pods -n monitoring
4οΈβ£ Check the running ports of the Prometheus pod:
kubectl describe pod <your-prometheus-pod-name> -n monitoring
5οΈβ£ Expose the Prometheus service:
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-exp -n monitoring
6οΈβ£ Verify the exposed service:
kubectl get svc -n monitoring
7οΈβ£ Access Prometheus in the browser:
minikube service prometheus-server-exp -n monitoring

1οΈβ£ Add the Grafana Helm repository:
helm repo add grafana https://grafana.github.io/helm-charts
2οΈβ£ Install Grafana:
helm install grafana grafana/grafana -n monitoring
3οΈβ£ Get the default Grafana admin password:
kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}"
π Decode the base64-encoded password using a third-party tool or command-line utility.

4οΈβ£ Check the running ports of the Grafana pod:
kubectl describe pod <your-grafana-pod-name> -n monitoring
5οΈβ£ Expose the Grafana service:
kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-exp -n monitoring
6οΈβ£ Access Grafana in the browser:
minikube service grafana-exp -n monitoring

1οΈβ£ In Grafana, navigate to Settings β Data Sources β Add Data Source.

2οΈβ£ Select **Prometheus**.

3οΈβ£ Use the following URL:
http://<your-minikube-ip>:<grafana-port-address>

4οΈβ£ Click Save & Test to confirm the connection.

Grafana provides pre-built dashboards for Kubernetes monitoring:
1οΈβ£ Go to Dashboards β Import.

2οΈβ£ Enter Dashboard ID: 3662
.
3οΈβ£ Select the Prometheus data source and click Import.

You should now see real-time metrics from your Minikube cluster! As shown belowπ

Congratulations! You have successfully set up Prometheus and Grafana on Minikube. You can now:
- Monitor CPU, memory, and network usage.
- Visualize real-time metrics with Grafana dashboards.
- Set up alerts using Alertmanager.
To further improve your monitoring setup, consider configuring Alertmanager for notifications and exploring custom dashboards.
π Next Steps:
- Learn more about Prometheus Query Language (PromQL).
- Customize Grafana dashboards to fit your needs.
- Set up monitoring for real-world Kubernetes clusters using kube-prometheus.
π Useful Links: