Step-by-Step Guide: Deploying a Kubernetes Observability Stack on WSL 2 (Prometheus & Grafana)

Running Kubernetes locally on Windows via WSL 2 can sometimes throw networking curveballs—especially when trying to connect your host browser to cluster services. This guide walks through the exact sequence to spin up Minikube, deploy Prometheus and Grafana via Helm, fix local port-forwarding errors, and visualize live cluster metrics.



Step 1: Initialize Your Minikube Cluster

First, ensure your local environment has enough resources allocated to handle containerized monitoring tools like Prometheus and Grafana. Fire up your WSL 2 terminal and start Minikube with increased CPU and memory:


minikube start --cpus=4 --memory=4096

Step 2: Create a Dedicated Monitoring Namespace

Instead of cluttering your default namespace, keep your observability stack organized in its own namespace:

kubectl create namespace monitoring

Step 3: Deploy Prometheus & Grafana Using Helm

Add the official Prometheus community Helm repository and install both Prometheus (the metrics database and scraper) and Grafana (the visualization dashboard) directly into your monitoring namespace:

# Add and update the Helm repo
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
# Install Prometheus and Grafana helm install prometheus prometheus-community/prometheus --namespace monitoring helm install grafana grafana-community/grafana --namespace monitoring

Step 4: Handle the Port-Forwarding Error & Apply the Fix

The Problem

To view Grafana in your web browser, you might normally try standard Kubernetes port forwarding:

kubectl port-forward deployment/grafana 3000:3000 -n monitoring

The Error: You will likely hit a Connection Refused or socket reset error. Because Minikube runs inside an isolated container network sandbox within WSL 2 and Docker Desktop, host-level port forwarding fails to bridge the virtualization boundary properly.

The Fix

Bypass kubectl port-forward entirely by using Minikube's native service routing bridge:

minikube service grafana -n monitoring

This command automatically opens a stable tunnel and provides a direct, accessible URL on your local machine (e.g., [http://127.0.0.1](http://127.0.0.1):xxxxx) that your Windows web browser can reach without dropping connections.

Step 5: Log Into Grafana and Connect Prometheus

  1. Open the URL provided by the minikube service command in your browser.

  2. Retrieve your admin password by running this command in your terminal:

    kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
  3. Log into Grafana using username admin and the decoded password.

  4. Go to Data Sources and click Add data source -> Prometheus.

  5. Crucial FQDN Setting: Do not use http://localhost:9090 (which causes an internal container loop error). Instead, use the internal Kubernetes CoreDNS service address:

    Plaintext
    http://prometheus-server.monitoring.svc.cluster.local
    
  6. Click Save & test. You should see the success confirmation: "Successfully queried the Prometheus API".

Step 6: Import the Kubernetes Overview Dashboard

  1. In Grafana, navigate to the sidebar and click Dashboards -> New -> Import.

  2. Enter the community dashboard ID: 14623 (Kubernetes Monitoring Overview) and click Load.

  3. At the bottom of the screen, select your newly linked Prometheus data source from the dropdown menu.

  4. Click Import.

Your dashboard will instantly populate with real-time graphs tracking your cluster's CPU utilization, memory usage, node health, and active pod lifecycles!




No comments: