Day 17: Visualizing Data with Grafana
Welcome to Day 17 of the Zero to Platform Engineer in 30 Days challenge! 🚀 Today, we’re focusing on visualizing Kubernetes metrics with Grafana, creating real-time dashboards to monitor application performance.
Why Use Grafana ?
Grafana is an open-source observability platform that helps you:
- Visualize metrics from Prometheus, Loki, and other data sources.
- Create dynamic dashboards for monitoring infrastructure and applications.
- Set up alerts to detect performance issues in real-time.
🎯 Key Benefits:
- Supports multiple data sources (Prometheus, Loki, InfluxDB, etc.).
- Interactive dashboards for real-time monitoring.
- Configurable alerts for proactive issue resolution.
Hands-On: Setting Up Grafana for Kubernetes
Step 1: Install Grafana with Helm
- Add the Grafana Helm repository:
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
- Install Grafana in your Kubernetes cluster:
helm install grafana grafana/grafana --namespace monitoring --create-namespace
- Verify that Grafana is running:
kubectl get pods -n monitoring
Step 2: Access Grafana
- Forward Grafana to your local machine:
kubectl port-forward svc/grafana -n monitoring 3000:80
- Open Grafana in your browser:
👉 http://localhost:3000
- Retrieve the admin password:
kubectl get secret grafana -n monitoring -o jsonpath="{.data.admin-password}" | base64 -d
- Login:
- Username:
admin
- Password:
Retrieved from the previous command
.
Step 3: Connect Prometheus as a Data Source
- In the Grafana UI, go to Configuration > Data Sources.
- Click Add data source and select Prometheus.
- Enter the Prometheus URL:
http://prometheus-kube-prometheus-prometheus.monitoring.svc.cluster.local:9090
- Click Save & Test to confirm the connection.
Step 4: Import a Pre-Built Kubernetes Dashboard
- Go to Dashboards > Import.
- Enter Dashboard ID: 3119 (Kubernetes Cluster Monitoring).
- Select Prometheus as the data source.
- Click Import to visualize your cluster metrics.
Step 5: Create a Custom Dashboard
- Go to Create > Dashboard.
- Add a Graph Panel and use the following PromQL queries:
- CPU Usage:
sum(rate(container_cpu_usage_seconds_total[5m])) by (pod)
- Memory Usage:
sum(container_memory_usage_bytes) by (pod)
- Request Rates:
rate(http_requests_total[1m])
- Click Save to store your custom dashboard.
Step 6: Set Up Alerts in Grafana
- Navigate to Alerting > Contact Points and add Slack, Email, or PagerDuty.
- Create a new Alert Rule:
- Condition: CPU usage > 85% for 2 minutes.
- Notification: Send to configured contact points.
- Click Save to activate alerts.
Activity for Today
- Deploy Grafana and connect it to Prometheus.
- Import a pre-built Kubernetes dashboard.
- Create a custom dashboard with key performance metrics.
- Set up alerts for proactive monitoring.
What’s Next?
Tomorrow, we’ll explore distributed tracing with OpenTelemetry, gaining deeper insights into request flows across microservices.
👉 Check it out here: Zero to Platform Engineer Repository
Feel free to clone the repo, experiment with the code, and even contribute if you’d like! 🚀
Follow the Series!
🎉 Don’t miss a single step in your journey to becoming a Platform Engineer! 🎉
This post is just the beginning. Here’s what we’ve covered so far and what’s coming up next:
-
Day 2: Day 2: Containers and Docker - The Building Blocks of Cloud Native
-
Day 3: Containers and Kubernetes - The Building Blocks of Cloud Native
-
Day 4: Deployments and Scaling in Kubernetes - Let’s Get Practical
-
Day 6: ConfigMaps and Secrets – Managing Configurations in Kubernetes
👉 Bookmark this blog and check back every day for new posts in the series. 📣 Share your progress on social media with the hashtag #ZeroToPlatformEngineer to connect with other readers!