Monitoring Kubernetes with Prometheus and Grafana
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
Monitoring is a critical aspect of Kubernetes administration, providing insights into the health and performance of clusters and applications. Prometheus and Grafana are popular tools for monitoring Kubernetes environments. Prometheus collects and stores metrics as time series data, while Grafana is used for visualizing and querying the data collected by Prometheus.
A running Kubernetes cluster.
Helm installed: Helm is a package manager for Kubernetes, which simplifies deploying applications on Kubernetes.
Add the Prometheus Helm Chart Repository:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
Install Prometheus:
Install Prometheus using the Helm chart:
helm install prometheus prometheus-community/prometheus
This command installs Prometheus with default settings. For custom configurations, you can create a values.yaml
file and pass it with the installation command.
Install Grafana:
Add the Grafana Helm Chart Repository:
Install Grafana using Helm:
After installation, both Prometheus and Grafana services are usually exposed as ClusterIP by default. To access them, you might need to change the service type to NodePort or LoadBalancer, or use port forwarding.
For Grafana, you will need the admin password, which can be obtained by:
kubectl get secret --namespace default grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
Configure Prometheus to Discover Targets:
Prometheus discovers targets through Service Discovery. Ensure your application exposes metrics in a format that Prometheus can scrape.
Configure Prometheus by editing its config map to include the scrape configuration for your application.
Visualize Metrics in Grafana:
Access Grafana's dashboard, typically at http://<NodeIP>:<NodePort>
.
Log in using the default username (admin
) and the password obtained earlier.
Let's say you have a Kubernetes application with Prometheus metrics exposed on /metrics
endpoint.
Update the Prometheus scrape config to include your application. This can be done by editing the prometheus.yaml
in the Prometheus ConfigMap and adding your application under scrape_configs
.
Once Prometheus is configured and restarted, it should begin scraping metrics from your application.
In Grafana, create a dashboard or import an existing one, and configure it to display the metrics collected from your application.
Monitoring Kubernetes with Prometheus and Grafana provides deep insights into the performance and health of your clusters and applications. Using Helm to install these tools simplifies the process and allows for customizable configurations. Regularly monitoring your Kubernetes environment is key to maintaining a healthy and efficient system.
Import or create a dashboard in Grafana to visualize the metrics. You can use community dashboards or create custom ones according to your monitoring needs.
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm install grafana grafana/grafana