Monitoring with Prometheus'

Author: Fabrice JAMMES (LinkedIn).

Prerequisites

# Launch the toolbox
ktbx desk

# Check your use kind-kind context
kubectx

#Launch initialization script
/home/k8s0/openshift-advanced/labs/3_policies/ex4-network.sh

# go to correct namespace
kubens network-k8s<ID>

Kubernetes Monitoring Lab with Helm

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.

Create Namespace

NS="monitoring"
kubectl create namespace "$NS"
kubectl label ns "$NS" "name=$NS"

Add and Update Helm Repositories

helm 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

Install Prometheus Stack

helm install --version "69.3.0" prometheus-stack prometheus-community/kube-prometheus-stack -n "$NS"  -f "$DIR"/values.yaml --create-namespace

6. Access Prometheus and Grafana

Once the deployment is complete, follow these exercises to interact with the monitoring stack:

  1. Watch all pods in the monitoring namespace:

    Answer
    kubectl get pods -n monitoring --watch

  2. Retrieve Grafana password:

    Answer
    helm show values prometheus-community/kube-prometheus-stack | grep adminPassword

  3. Port forward Grafana to access it in a web browser:

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

    Then open your browser and go to: http://localhost:3000

Cleanup

To remove the deployed stack:

helm delete prometheus-stack -n "$NS"
kubectl delete namespace "$NS"

Conclusion

This lab guides you through deploying a monitoring stack using Helm and Kubernetes, allowing you to explore Prometheus and Grafana for cluster monitoring.