This lab runs on the kind cluster shared by all trainees: switch to it first with kubectx kind-kind.
Objective
The goal of this lab is to deploy the Prometheus Stack using Helm while following best practices in shell scripting.
Prerequisites
Ensure you have the following installed:
Kubernetes cluster (e.g., Minikube, Kind, or a cloud-managed cluster)
kubectl configured to access the cluster
helm installed
bash shell
Steps to Deploy Prometheus Stack
Note
The Prometheus installation is completed before the lab; the following instructions are for reference only.
Install Prometheus Stack
git clone https://github.com/k8s-school/demo-prometheus
cd demo-prometheus
./install.sh
6. Access Prometheus and Grafana
Once the deployment is complete, follow these exercises to interact with the monitoring stack:
Watch all pods in the monitoring namespace:
Answer
kubectl get pods -n monitoring --watch
Find the Prometheus operator and the CRDs it manages:
Which Custom Resource Definitions were installed by the stack? Which pod is the operator, and which objects does it reconcile into StatefulSets?
Answer
# CRDs installed by the Prometheus operator (API group monitoring.coreos.com)kubectl get crd | grep monitoring.coreos.com
kubectl api-resources --api-group=monitoring.coreos.com
# The operator itself is a plain Deploymentkubectl get deployments -n monitoring | grep operator
# Custom resources watched by the operatorkubectl get prometheuses,alertmanagers,servicemonitors,prometheusrules -n monitoring
# The Prometheus StatefulSet is created by the operator, from the Prometheus custom resourcekubectl get statefulsets -n monitoring
kubectl get statefulset -n monitoring prometheus-prometheus-stack-kube-prom-prometheus \
-o jsonpath='{.metadata.ownerReferences[*].kind}{"/"}{.metadata.ownerReferences[*].name}{"\n"}'
Retrieve Grafana password:
Answer
# Add helm repositoryhelm repo add prometheus-community https://prometheus-community.github.io/helm-charts || echo "Unable to add repo prometheus-community"helm repo add stable https://charts.helm.sh/stable --force-update
helm repo update
# Query helm configuration, for the chart version installed by demo-prometheushelm show values --version 69.3.0 prometheus-community/kube-prometheus-stack | grep adminPassword
# Or read it from the Grafana secretkubectl get secret -n monitoring prometheus-stack-grafana -o jsonpath='{.data.admin-password}' | base64 -d
Port forward Prometheus web UI to access it in a web browser:
Eventually create a ssh tunnel if Kubernetes is secured behind a ssh bastion. On a server shared by several trainees, pick a local port of your own (e.g. 909<ID>:9090).
This lab guides you through deploying a monitoring stack using Helm and Kubernetes, allowing you to explore Prometheus and Grafana for cluster monitoring.