In this article, we will learn Monitor Kubernetes Cluster using Prometheus and Grafana | How to Monitor Kubernetes Using Prometheus and Grafana. Kubernetes monitoring is essential for understanding the health and performance of your cluster. Prometheus and Grafana are popular tools that simplify the monitoring process. This article walks through the setup process for monitoring Kubernetes using Minikube, Prometheus, and Grafana.
Table of Contents
Prerequisites
- AWS Account with Ubuntu 24.04 LTS EC2 Instance.
- Minikube and kubectl, Helm Installed
- Basic knowledge of Kubernetes
Step #1:Set Up Ubuntu EC2 Instance
Update the Package List.
sudo apt update

Installs essential tools like curl, wget and apt-transport-https.
sudo apt install curl wget apt-transport-https -y

Installs Docker, a container runtime that will be used as the VM driver for Minikube.
sudo apt install docker.io -y

Add the current user to the Docker group, allowing the user to run Docker commands without sudo
.
sudo usermod -aG docker $USER

Adjust permissions for the Docker socket, enabling easier communication with the Docker daemon.
sudo chmod 666 /var/run/docker.sock

Checks if the system supports virtualization.
egrep -q 'vmx|svm' /proc/cpuinfo && echo yes || echo no

Install KVM and Related Tools.
sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon

Add User to Virtualization Groups.
sudo adduser $USER libvirt
sudo adduser $USER libvirt-qemu

Reload Group.
newgrp libvirt
newgrp libvirt-qemu

Step #2:Install Minikube and kubectl
Download the latest Minikube binary.
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

Install it to /usr/local/bin
, making it available system-wide.
sudo install minikube-linux-amd64 /usr/local/bin/minikube

Use minikube version command to confirm the installation.
minikube version

Download the latest version of kubectl
(Kubernetes CLI).
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

Make the kubectl binary executable.
chmod +x ./kubectl

move it to /usr/local/bin
sudo mv kubectl /usr/local/bin/

Use kubectl version command to check the installation.
kubectl version --client --output=yaml

Step #3:Start the Minikube
Start Minikube with Docker as the driver.
minikube start --vm-driver docker

To Check the status of Minikube run the following command.
minikube status

Step #4:Install the Helm
Download the helm, a package manager for Kubernetes.
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3

Change its permissions.
chmod 700 get_helm.sh

Install the helm.
./get_helm.sh

Check its version to confirm the installation.
helm version

Add Prometheus Helm Chart Repository.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

update the Helm repositories to fetch the latest charts.
helm repo update

Step #5:Configure Prometheus and Grafana
Create a custom-values.yaml file to configure Prometheus and Grafana services as NodePort
nano custom-values.yaml

Add the following configuration.
prometheus:
service:
type: NodePort
grafana:
service:
type: NodePort

Deploy the Prometheus and Grafana stack.
helm upgrade --install kube-prometheus-stack prometheus-community/kube-prometheus-stack -f custom-values.yaml

Step #6:Access Prometheus and Grafana
List the services to get NodePort details.
kubectl get services

Forward the Prometheus service to port 9090.
kubectl port-forward --address 0.0.0.0 svc/kube-prometheus-stack-prometheus 9090:9090

Access the UI of Prometheus on web browser using http://<EC2-Public-IP>:9090
.

Click on alerts to see them.

Open the duplicate tab and Forward the Grafana service to port 3000.
kubectl port-forward --address 0.0.0.0 svc/kube-prometheus-stack-grafana 3000:80

Access the UI of Grafana on web browser using http://<EC2-Public-IP>:3000
.

Retrieve Grafana admin credentials using following commands.
kubectl get secret --namespace default kube-prometheus-stack-grafana -o jsonpath="{.data.admin-user}" | base64 --decode ; echo

admin is our Username.
kubectl get secret --namespace default kube-prometheus-stack-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

prom-operator is our password.

Step #7:Use Grafana Dashboards
Go to Dashboards.

You can see the few default dashboards there.

There are many dashboards you can use, using these dashboards we can easily monitor our kubernetes cluster. For example below is Kubernetes/API sever dashboard.

You can also import dashboards from the Grafana library.
Access the Grafana library. Search for Grafana Labs in web browser.

Select a desired dashboard, e.g., 11455
for K8s/Storage/Volumes/Namespace.
Search for K8s/Storage/Volumes/Namespace


Copy its ID.

In Grafana, go to Dashboards > New > Import.

Enter the dashboard ID (11455
) and click Load.

Select Prometheus as a data source and Click Import to add the dashboard..


Conclusion:
In conclusion, today we have successfully set up Kubernetes monitoring with Prometheus and Grafana. We have seen the step to install tools, configure a Kubernetes cluster, and deploy monitoring solutions. Using Prometheus and Grafana, you gain powerful insights into your cluster’s performance. Use the default and custom dashboards to monitor the health and performance of your Kubernetes cluster. You can extend this setup to include alerting and custom metrics for deeper insights.
Related Articles:
Pull Image from DockerHub Private Registry using Helm in Kubernetes
Reference: