0
0
KubernetesHow-ToBeginner · 4 min read

How to Use Grafana with Kubernetes: Setup and Monitoring Guide

To use Grafana with Kubernetes, deploy Grafana in your cluster using Helm or manifests, then connect it to a data source like Prometheus that collects Kubernetes metrics. Finally, access Grafana’s web UI to create dashboards and visualize your cluster’s health and performance.
📐

Syntax

Deploying Grafana on Kubernetes typically involves these steps:

  • Install Prometheus: Collects metrics from Kubernetes.
  • Deploy Grafana: Use Helm or YAML manifests.
  • Configure Data Source: Connect Grafana to Prometheus.
  • Access UI: Use port-forward or LoadBalancer to open Grafana dashboard.
bash
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/prometheus
helm install grafana grafana/grafana
kubectl port-forward svc/grafana 3000:80
💻

Example

This example shows how to install Prometheus and Grafana using Helm, then access Grafana UI to visualize Kubernetes metrics.

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

# Install Prometheus for metrics collection
helm install prometheus prometheus-community/prometheus

# Install Grafana for visualization
helm install grafana grafana/grafana

# Forward Grafana service port to localhost
kubectl port-forward svc/grafana 3000:80
Output
Forwarding from 127.0.0.1:3000 -> 80 Forwarding from [::1]:3000 -> 80
⚠️

Common Pitfalls

1. Missing Data Source: Forgetting to configure Prometheus as Grafana’s data source will show empty dashboards.

2. Access Issues: Not forwarding ports or exposing Grafana service properly blocks UI access.

3. Permissions: Prometheus must have permissions to scrape Kubernetes metrics.

none
### Wrong: No data source configured in Grafana
# Grafana dashboards will be empty

### Right: Add Prometheus data source in Grafana UI or via config
# URL: http://prometheus-server.default.svc.cluster.local:80
# Type: Prometheus
📊

Quick Reference

  • Helm Repos: prometheus-community, grafana
  • Key Commands: helm install, kubectl port-forward
  • Access Grafana: http://localhost:3000 (default user: admin, password from secret)
  • Data Source URL: Prometheus service URL inside cluster

Key Takeaways

Deploy Prometheus first to collect Kubernetes metrics before installing Grafana.
Use Helm charts for easy installation of Prometheus and Grafana on Kubernetes.
Configure Grafana to use Prometheus as its data source to visualize metrics.
Access Grafana UI via port-forward or LoadBalancer to create and view dashboards.
Check permissions and service URLs to avoid common setup issues.