DEV Community

Cover image for Using Helm Chart to Deploy Grafana, Prometheus, and Loki Data Source on Your Kubernetes Cluster
CYRIL OSSAI
CYRIL OSSAI

Posted on

Using Helm Chart to Deploy Grafana, Prometheus, and Loki Data Source on Your Kubernetes Cluster

Deploying observability tools like Grafana, Prometheus, and Loki in a Kubernetes environment can seem complex at first. But with Helm, the package manager for Kubernetes, you can streamline this process, allowing you to deploy and manage these services easily. Helm charts provide reusable, pre-configured Kubernetes resources, helping to automate the deployment of complex applications.

I’ll walk you through how to deploy Grafana, Prometheus, and Loki on your Kubernetes cluster using Helm charts.

Prerequisites
Before getting started, ensure the following are set up:

  1. Kubernetes Cluster: A functioning Kubernetes cluster with kubectl configured.
  2. Helm: Ensure Helm is installed on your system. You can install Helm by following the official Helm installation guide.
  3. kubectl: Have kubectl set up to interact with your Kubernetes cluster.

Step 1: Add the Helm Repositories
First, you'll need to add the necessary Helm repositories for Prometheus, Grafana, and Loki.

  1. Add the Prometheus Community Helm Repo:

*helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
*

2. Add the Grafana Helm Repo:

helm repo add grafana https://grafana.github.io/helm-charts

3. Update Your Repositories: Always ensure you have the latest version of the charts:

helm repo update

Step 2: Install Prometheus
Prometheus is a key monitoring tool used to scrape and store metrics. You can deploy it using Helm with just a few commands:
1. Install Prometheus using the Helm chart from the Prometheus community:

code below
helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace

2. Verify Installation: Ensure Prometheus is running by listing the pods in the monitoring namespace:

code below:
kubectl get pods -n monitoring
You should see pods for Prometheus server, Alertmanager, and other Prometheus components.

Step 3: Install Grafana
Grafana is a powerful dashboard tool that integrates with Prometheus to visualize metrics. Installing Grafana with Helm is just as easy:

  1. Install Grafana using the Helm chart:

Copy code below
helm install grafana grafana/grafana --namespace monitoring

**2. Expose Grafana (optional): **To access Grafana via a browser, you can expose it using a LoadBalancer or NodePort. For example, to expose using a LoadBalancer:

Copy code below
kubectl expose service grafana --type=LoadBalancer --name=grafana-ext --namespace monitoring
3. Retrieve Grafana Credentials: By default, Grafana generates an admin password which you can retrieve with the following command:

Copy code below
kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
The username is admin by default.

Step 4: Install Loki for Log Aggregation
Loki is a log aggregation system that works perfectly with Prometheus and Grafana to give a full observability stack. Use Helm to deploy Loki alongside Prometheus and Grafana.

1. Install Loki using the Grafana Helm chart repository:

code
helm install loki grafana/loki-stack --namespace monitoring

2. Verify Installation: Ensure Loki is running properly:
bash
Copy code
kubectl get pods -n monitoring
You should see a pod running for loki and potentially a promtail agent.

Step 5: Configure Grafana to Use Prometheus and Loki
Now that Grafana, Prometheus, and Loki are running, the final step is to configure Grafana to use Prometheus as the data source for metrics and Loki for logs.

1. Access Grafana: If you exposed Grafana as a service, open it in your browser using the external IP. If not, use kubectl port-forward to access it locally:
code
kubectl port-forward svc/grafana 3000:80 -n monitoring
Then, open your browser and go to http://localhost:3000.
2. Add Prometheus as a Data Source:
o In the Grafana dashboard, go to Configuration > Data Sources.
o Click Add data source and select Prometheus.
o For the URL, enter the Prometheus service URL. If you're running Prometheus within Kubernetes, you can find this by running:

kubectl get svc -n monitoring
The URL should be similar to http://prometheus-server.monitoring.svc.cluster.local:80.
o Click Save & Test to verify the connection.
3. Add Loki as a Data Source:
o Similarly, in Data Sources, add Loki.
o Use the service URL for Loki, which can be found by:

kubectl get svc -n monitoring
The URL for Loki should be something like http://loki.monitoring.svc.cluster.local:3100.
o Click Save & Test to confirm the connection.

Step 6: Create Dashboards
With both Prometheus and Loki set as data sources, you can now create Grafana dashboards to visualize your system's performance and logs. Here’s how to create basic dashboards:
1. Import Pre-built Dashboards:
o Grafana has a range of community-contributed dashboards for Prometheus and Loki. Go to Dashboards > Import, and use dashboard IDs like:
 Prometheus Kubernetes Cluster Monitoring: ID 315
 Loki Logging Dashboard: ID 11074
o Import these dashboards and configure them to use your Prometheus and Loki data sources.
2. Create Custom Dashboards:
o Alternatively, you can create custom dashboards tailored to your environment. Choose New Dashboard, add a panel, and select Prometheus or Loki as the data source.

Conclusion
By using Helm, you’ve streamlined the process of deploying Prometheus, Grafana, and Loki onto your Kubernetes cluster. These tools provide a comprehensive observability stack, allowing you to monitor metrics, logs, and alerts with ease. With Prometheus scraping metrics, Loki aggregating logs, and Grafana visualizing it all, you’re well-equipped to manage and maintain the health of your Kubernetes environment.

Look out for my next article on Deploying a Monitoring Stack using kubectl and Helm, deploying Grafana, Loki, and Prometheus to your cluster, and setting up Ingress for external access.

Top comments (0)