Introduction
In modern DevOps workflows, monitoring Kubernetes clusters is crucial to ensure optimal performance, resource allocation, and overall system health. While tools like Prometheus and Grafana provide powerful insights, default dashboards may not always meet the needs of different teams.
In this post, I’ll walk you through the process of creating custom Grafana dashboards to monitor Kubernetes resources, making monitoring data more accessible and actionable for different stakeholders.
Why Custom Dashboards?
A one-size-fits-all dashboard doesn’t always work in dynamic environments. Different teams require different levels of detail:
- Developers might want insights into application performance and error rates.
- SREs and Ops teams need deep infrastructure metrics like CPU, memory, and pod statuses.
- Management and Business teams may prefer high-level overviews of system health.
By creating role-specific visualizations, we can provide each team with the data they need.
Setting Up Grafana for Kubernetes Monitoring
Step 1: Install Prometheus and Grafana in Kubernetes
If you haven’t already installed Prometheus and Grafana, you can deploy them using Helm:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install monitoring prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace
After installation, forward the Grafana service to access the UI:
kubectl port-forward svc/monitoring-grafana 3000:80 -n monitoring
Now, open http://localhost:3000 and log in with:
- Username: admin
- Password: Retrieve it using:
kubectl get secret --namespace monitoring monitoring-grafana -o jsonpath="{.data.admin-password}" | base64 --decode
Step 2: Configure Prometheus as the Data Source
Once inside Grafana:
- Go to Configuration → Data Sources.
- Click Add data source and select Prometheus.
- Set the URL to http://monitoring-prometheus-oper-prometheus.monitoring.svc.cluster.local:9090.
- Click Save & Test to verify the connection.
Now, Grafana can fetch Kubernetes metrics from Prometheus.
Step 3: Creating a Custom Dashboard
We’ll manually create a Kubernetes Resource Monitoring dashboard in Grafana.
Adding a CPU Usage Panel
- Go to Dashboards → New Dashboard.
- Click Add a New Panel.
- Under Query, select Prometheus as the data source.
- Enter the following PromQL query to monitor CPU usage per namespace:
sum(rate(container_cpu_usage_seconds_total{namespace!='', container!=''}[5m])) by (namespace)
- In the Legend format, enter {{namespace}} to label the graph properly.
- Click Apply.
Adding a Memory Usage Panel
- Add another panel in the same dashboard.
- Use the following PromQL query to monitor Memory usage per namespace:
sum(container_memory_usage_bytes{namespace!='', container!=''}) by (namespace)
- Set the Legend format to {{namespace}}.
- Click Apply.
Saving the Dashboard
- Click Save Dashboard.
- Enter a name like Kubernetes Resource Monitoring.
- Click Save.
Step 4: Viewing the Dashboard
Once saved, the dashboard should display real-time CPU and memory usage graphs categorized by namespaces.
- SREs can track high CPU-consuming namespaces to optimize resource allocation.
- Developers can monitor application memory usage to debug performance issues.
- Managers can get an overview of cluster health at a glance.
By creating custom visualizations, we make Kubernetes monitoring more actionable and role-specific.
Conclusion
In this post, we explored how to create a custom Kubernetes monitoring dashboard in Grafana. By leveraging Prometheus metrics, we designed role-specific panels for CPU and memory usage, making monitoring more insightful and efficient.
Stay tuned for more Kubernetes insights! If you found this helpful, share your thoughts in the comments.![]()
Deploy Loki for log aggregation