Skip to main content

Lab 11.1 - Installing Prometheus and Grafana

Lab Objectives​

By the end of this lab, you will be able to:

  • Install Prometheus in Kubernetes.
  • Install Grafana in Kubernetes.
  • Configure Prometheus to collect metrics.
  • Access Grafana dashboards.
  • Understand the Prometheus-Grafana integration.

Estimated Duration​

60-75 minutes

Prerequisites​

  • kubectl installed and configured.
  • Working local Kubernetes cluster.
  • Helm installed (to facilitate installation).

Part 1: Installing Prometheus with Helm​

Step 1.1: Add the Prometheus Repository​

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

Step 1.2: Install Prometheus​

helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--create-namespace

Wait for the Pods to be ready:

kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=prometheus -n monitoring --timeout=300s

Part 2: Verifying the Installation​

Step 2.1: Verify Pods​

kubectl get pods -n monitoring

You should see:

  • prometheus-operator
  • prometheus-kube-prometheus-prometheus
  • grafana
  • kube-state-metrics
  • node-exporter

Step 2.2: Verify Services​

kubectl get svc -n monitoring

Part 3: Accessing Prometheus​

Step 3.1: Port-Forward to Prometheus​

kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090

Access http://localhost:9090 in your browser.

Step 3.2: Test PromQL Queries​

In the Prometheus interface, test:

up
container_memory_usage_bytes
kube_pod_info

Part 4: Accessing Grafana​

Step 4.1: Get the Password​

kubectl get secret --namespace monitoring prometheus-grafana -o jsonpath="{.data.admin-password}" | base64 --decode

The default username is admin.

Step 4.2: Port-Forward to Grafana​

kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80

Access http://localhost:3000 and log in.


Part 5: Exploring Dashboards​

Step 5.1: Pre-configured Dashboards​

Grafana comes with pre-configured dashboards:

  • Kubernetes / Compute Resources / Cluster
  • Kubernetes / Compute Resources / Namespace
  • Kubernetes / Compute Resources / Pod

Explore these dashboards.


Part 6: Cleanup​

helm uninstall prometheus -n monitoring
kubectl delete namespace monitoring

Lab Summary​

In this lab, you installed Prometheus and Grafana in Kubernetes. You learned how to access the interfaces, use PromQL, and explore Grafana dashboards.


Next Steps​

The next lab will show you how to create custom dashboards in Grafana.

Lab 11.2: Creating Custom Dashboards


Lab created on: December 2024