Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/moshclouds/monitoring-k8s-with-prometheus-and-grafana

Learn how to set up Prometheus and Grafana on Minikube for monitoring Kubernetes clusters. This beginner-friendly guide covers installation, service exposure, and dashboard visualization for real-time cluster insights. ๐Ÿš€๐Ÿ“Š
https://github.com/moshclouds/monitoring-k8s-with-prometheus-and-grafana

grafana helm kubernetes minikube observability prometheus

Last synced: about 11 hours ago
JSON representation

Learn how to set up Prometheus and Grafana on Minikube for monitoring Kubernetes clusters. This beginner-friendly guide covers installation, service exposure, and dashboard visualization for real-time cluster insights. ๐Ÿš€๐Ÿ“Š

Awesome Lists containing this project

README

        

# ๐Ÿš€ Monitoring Kubernetes with Prometheus and Grafana on Minikube


Image

## ๐Ÿ”ฅ Introduction

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.

---

## โœ… Prerequisites

Before we start, ensure you have the following installed:

- **Minikube** ([Install Guide](https://minikube.sigs.k8s.io/docs/start/))
- **kubectl** ([Install Guide](https://kubernetes.io/docs/tasks/tools/))
- **Helm** ([Install Guide](https://helm.sh/docs/intro/install/))

To verify Minikube is installed, run:
```sh
minikube version
```

---

## โš™๏ธ Step 1: Start Minikube

First, start your Minikube cluster:
```sh
minikube start
```
Check the status:
```sh
minikube status
```

---

## ๐Ÿ“ฆ Step 2: Create a Namespace for Monitoring

It's a good practice to keep monitoring components in a separate namespace.
```sh
kubectl create namespace monitoring
```

---

## ๐Ÿ“ก Step 3: Deploy Prometheus

1๏ธโƒฃ Add the **Prometheus Helm repository**:
```sh
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
```

2๏ธโƒฃ Install **Prometheus**:
```sh
helm install prometheus prometheus-community/prometheus -n monitoring
```

3๏ธโƒฃ Verify the installation:
```sh
kubectl get pods -n monitoring
```

4๏ธโƒฃ Check the running ports of the Prometheus pod:
```sh
kubectl describe pod -n monitoring
```

5๏ธโƒฃ Expose the Prometheus service:
```sh
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-exp -n monitoring
```

6๏ธโƒฃ Verify the exposed service:
```sh
kubectl get svc -n monitoring
```

7๏ธโƒฃ Access Prometheus in the browser:
```sh
minikube service prometheus-server-exp -n monitoring
```
Image

---

## ๐Ÿ“Š Step 4: Deploy Grafana

1๏ธโƒฃ Add the **Grafana Helm repository**:
```sh
helm repo add grafana https://grafana.github.io/helm-charts
```

2๏ธโƒฃ Install **Grafana**:
```sh
helm install grafana grafana/grafana -n monitoring
```

3๏ธโƒฃ Get the default Grafana admin password:
```sh
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.

Image


4๏ธโƒฃ Check the running ports of the Grafana pod:
```sh
kubectl describe pod -n monitoring
```

5๏ธโƒฃ Expose the Grafana service:
```sh
kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-exp -n monitoring
```

6๏ธโƒฃ Access Grafana in the browser:
```sh
minikube service grafana-exp -n monitoring
```

Image


---

## ๐Ÿ› ๏ธ Step 5: Add Prometheus as a Data Source in Grafana

1๏ธโƒฃ In Grafana, navigate to **Settings โ†’ Data Sources โ†’ Add Data Source**.

Image



2๏ธโƒฃ Select **Prometheus**.

Image



3๏ธโƒฃ Use the following URL:

```
http://:
```
Image


4๏ธโƒฃ Click **Save & Test** to confirm the connection.

Image


---

## ๐Ÿ“ˆ Step 6: Import Kubernetes Dashboards in Grafana

Grafana provides pre-built dashboards for Kubernetes monitoring:

1๏ธโƒฃ Go to **Dashboards โ†’ Import**.

Image


2๏ธโƒฃ Enter **Dashboard ID:** `3662`.

Image

3๏ธโƒฃ Select the Prometheus data source and click **Import**.

Image


You should now see real-time metrics from your Minikube cluster! As shown below๐ŸŽ‰

Image


---

## ๐ŸŽฏ Conclusion

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:
- [Prometheus Docs](https://prometheus.io/docs/)
- [Grafana Docs](https://grafana.com/docs/)
- [Helm Charts](https://github.com/prometheus-community/helm-charts)