Use the kube-prometheus-stack Helm chart to deploy both Prometheus and Grafana automatically. Prometheus scrapes pod metrics generated by cAdvisor and kube-state-metrics, which you then visualize by importing a pre-built Kubernetes dashboard in Grafana.
1. Deploy the Monitoring Stack
Using Helm is the easiest way to deploy everything required to your cluster.
bash
# Add the necessary Helm repositories
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
# Create a dedicated namespace and install the stack
kubectl create namespace monitoring
helm install prometheus-stack prometheus-community/kube-prometheus-stack --namespace monitoring2. Access the Dashboards
To view your data, expose the services locally using port-forwarding:
Grafana
bash
# Forward Grafana to port 3000
kubectl port-forward svc/prometheus-stack-grafana -n monitoring 3000:80
Navigate to http://localhost:3000. The default username is admin. Retrieve the auto-generated password by running:
kubectl get secret --namespace monitoring prometheus-stack-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
Prometheus
bash
# Forward Prometheus to port 9090
kubectl port-forward svc/prometheus-stack-kube-prome-prometheus -n monitoring 9090:9090
Navigate to http://localhost:9090 to run direct PromQL queries.
3. Visualize Pod Metrics in Grafana
Once logged into Grafana:
-
Go to
Connections > Data Sources. -
Add Prometheus and use the internal cluster URL
http://cluster.local. -
Go to
Dashboards > Import. -
Enter the Dashboard ID
6417(Kubernetes Cluster) or15760(Node Exporter), select your Prometheus data source, and click Import.
No comments:
Post a Comment