Monitoring Kubernetes Made Easy: Installing Prometheus and Grafana via Helm
In the ever-evolving landscape of cloud-native technologies, Kubernetes has emerged as the de facto standard for orchestrating containerized applications. Monitoring these applications and the underlying infrastructure is crucial to ensuring their reliability and performance. Two popular tools for achieving this are Prometheus and Grafana. In this blog post, we’ll walk you through the process of setting up Prometheus and Grafana monitoring on a Kubernetes cluster using Helm, a package manager for Kubernetes applications.
Why Prometheus and Grafana?
Prometheus is an open-source monitoring and alerting toolkit that collects time-series data about your infrastructure and applications. It’s designed for reliability, scalability, and ease of use. Grafana, on the other hand, is a popular open-source platform for monitoring and observability. It enables you to visualize data collected by Prometheus and other data sources through dynamic and customizable dashboards.
Prerequisites
Before we dive into the setup process, make sure you have the following prerequisites:
- A Kubernetes cluster up and running. you can check out my previous blog post on Kubernetes Roadmap Demystified: Your Journey from Beginner to Kubernetes Pro to install minikube
- Helm installed on your local machine and configured to work with your Kubernetes cluster.
Step 1: Installing Prometheus with Helm
- Open your terminal and navigate to the directory where you want to install Prometheus.
- Run the following command to add the Prometheus Helm chart repository:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
3. Update the local Helm chart repository cache:
helm repo update
4. Install Prometheus using Helm with a release name (e.g., prometheus-release
):
helm install prometheus-release prometheus-community/prometheus
5. Verify that Prometheus components are deployed:
kubectl get pods
Step 2: Installing Grafana with Helm
- Add the Grafana Helm chart repository:
helm repo add grafana https://grafana.github.io/helm-charts
2. Update the Helm repository cache:
helm repo update
3. Install Grafana using Helm with a release name (e.g., grafana-release
):
helm install grafana-release grafana/grafana
4. Get the Grafana admin password:
kubectl get secret grafana-release -o jsonpath='{.data.admin-password}' -n grafana-release | base64 --decode ; echo
5. Access the Grafana dashboard by port-forwarding:
kubectl port-forward svc/grafana-release 3000:80 -n grafana-release
Open your browser and navigate to http://localhost:3000
. Log in with the admin username (admin
) and the password from the previous step.
Step 3: Configuring Prometheus as a Data Source in Grafana
- Log in to your Grafana dashboard.
- Click on the gear icon (⚙️) on the left sidebar to open the Configuration menu, then select “Data Sources.”
- Click on “Add data source” and choose “Prometheus.”
- Configure the data source:
- Name: Prometheus
- URL:
http://prometheus-release-server.prometheus-release.svc.cluster.local
(replace with your Prometheus server's URL) - Access:
Server (default)
5. Click “Save & Test” to ensure the data source is working.
Step 4: Creating Dashboards in Grafana
- In Grafana, click on the “+” icon on the left sidebar and select “Dashboard.”
- Click on “Add new panel” to add a visualization to the dashboard.
- Choose the data source you configured earlier (Prometheus) from the “Panel Data Source” dropdown at the top of the panel.
- In the panel’s settings, select the “Code” option to directly input your query.
- Input the following query to get the status of pods in the Kubernetes cluster:
kube_pod_status_phase
6. Scroll down to the “Visualization” section and select the “Table” visualization type. This will display the pod status in a tabular format.
7. Customize the table settings, such as column names and sorting options, as needed.
8. Click “Apply” or “Save” to see the table displaying the status of pods in the cluster.
9. To add another panel for a different metric, click on the “+” icon next to your existing panel and choose “Add Panel Below.” Then repeat the process to add a new query for the desired metric.
By using the kube_pod_status_phase
metric in your query, you'll be able to see the current phase of each pod, which includes values like "Running," "Pending," "Failed," etc. This can provide valuable insights into the health and status of your Kubernetes pods.
Remember that Prometheus offers a wide range of metrics related to Kubernetes, and you can create custom queries to visualize various aspects of your cluster’s performance and health.
As always, consider the version of Grafana you’re using and any variations in the interface when following these steps.
Conclusion
By setting up Prometheus and Grafana using Helm on your Kubernetes cluster, you’ve established a robust monitoring solution. This combination allows you to gather valuable insights into the performance and health of your applications and infrastructure. With these tools at your disposal, you’re better equipped to ensure the reliability of your cloud-native deployments. Happy monitoring!
Thank you for reading my blog! If you enjoyed the content and want to receive timely updates whenever I publish a new article, make sure to follow me on Medium. It’s quick and easy! Just log in to your Medium account (or create one if you haven’t already), visit my profile, and click the “Follow” button. Stay informed and never miss a new post! Your support means a lot to me, and I’m excited to continue sharing valuable insights with you. Happy reading! 🚀