Helm Chart Installation
Introduction
Helm charts provide a streamlined way to deploy applications on Kubernetes clusters. For Grafana Loki, Helm charts offer a production-ready deployment method that simplifies the installation process and provides flexibility for customization. This guide will walk you through installing Grafana Loki using Helm charts, from prerequisites to verification.
What are Helm Charts?
Helm is often referred to as the "package manager for Kubernetes." Just as package managers like apt, yum, or npm help install software on operating systems or in projects, Helm helps deploy applications on Kubernetes clusters.
A Helm chart is a collection of pre-configured Kubernetes resources that:
- Defines all necessary components for an application
- Allows for configuration through values files
- Supports versioning and upgrades
- Simplifies complex deployments into a single command
Prerequisites
Before installing Grafana Loki using Helm charts, ensure you have:
- A running Kubernetes cluster
- Helm CLI installed on your local machine
kubectl
configured to communicate with your cluster
Let's verify these prerequisites:
# Check Kubernetes connection
kubectl cluster-info
# Verify Helm installation
helm version
Expected output for kubectl cluster-info
:
Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Expected output for helm version
:
version.BuildInfo{Version:"v3.12.3", GitCommit:"3a31588ad33fe3b89af5a2a54ee1d25bfe6eaa5e", GitTreeState:"clean", GoVersion:"go1.20.8"}
Step 1: Add the Grafana Helm Repository
First, we need to add the Grafana Helm repository to our local Helm configuration:
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
Expected output:
"grafana" has been added to your repositories
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "grafana" chart repository
Update Complete. ⎈Happy Helming!⎈
Step 2: Create a Values File
Helm charts accept customization through values files. Create a file named loki-values.yaml
with your desired configuration:
loki:
auth_enabled: false
storage:
type: filesystem
persistence:
enabled: true
size: 10Gi
serviceMonitor:
enabled: true
gateway:
enabled: true
This configuration:
- Disables authentication for learning purposes (enable in production)
- Uses filesystem storage (simplest option for beginners)
- Enables persistence with a 10GB volume
- Sets up Prometheus monitoring
- Enables the Loki gateway component
Step 3: Install Loki using Helm
Now we can install Loki using our values file:
helm install loki grafana/loki-stack -f loki-values.yaml --namespace loki --create-namespace
Expected output:
NAME: loki
LAST DEPLOYED: Thu Mar 28 14:23:15 2025
NAMESPACE: loki
STATUS: deployed
REVISION: 1
NOTES:
The Loki stack has been deployed to your cluster.
Loki can be accessed via port 3100 on the following DNS name from within your cluster:
loki.loki.svc.cluster.local
To access Loki from outside the cluster:
1. Get the Loki URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace loki -l "app=loki" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 3100:3100 --namespace loki
echo "Visit http://127.0.0.1:3100 to access Loki"
Step 4: Verify the Installation
Check that all pods are running correctly:
kubectl get pods -n loki
Expected output:
NAME READY STATUS RESTARTS AGE
loki-0 1/1 Running 0 3m32s
loki-gateway-5f496c9887-2xnbt 1/1 Running 0 3m32s
loki-promtail-kt7xl 1/1 Running 0 3m32s
If any pods aren't in the Running
state, you can check their logs for troubleshooting:
kubectl logs -n loki loki-0
Step 5: Setup Port Forwarding
To access the Loki API locally:
kubectl port-forward service/loki-gateway 3100:80 -n loki
Now you can access Loki at http://localhost:3100/
in your browser or with tools like curl:
curl http://localhost:3100/ready
Expected output: ready
Step 6: Connect Grafana to Loki
If you have Grafana installed, add Loki as a data source:
- In Grafana UI, go to Configuration > Data Sources
- Click "Add data source"
- Select "Loki"
- For URL, enter:
- If Grafana is in the same Kubernetes cluster:
http://loki-gateway.loki.svc.cluster.local:80
- If using port forwarding:
http://localhost:3100
- If Grafana is in the same Kubernetes cluster:
- Click "Save & Test"
Customizing Your Loki Deployment
The Helm chart offers many configuration options. Here are some common customizations:
Scaling Loki Components
For higher performance, modify your values file:
loki:
replicas: 3
promtail:
enabled: true
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
Configuring Storage
For production environments, use object storage:
loki:
storage:
type: s3
s3:
s3: s3://region
bucketnames: my-loki-bucket
endpoint: s3.amazonaws.com
access_key_id: "${ACCESS_KEY}"
secret_access_key: "${SECRET_KEY}"
Upgrading Loki
To upgrade your Loki installation when new versions are released:
helm repo update
helm upgrade loki grafana/loki-stack -f loki-values.yaml --namespace loki
Uninstalling Loki
If needed, you can uninstall Loki with:
helm uninstall loki -n loki
To also remove persistent volumes:
kubectl delete pvc -l app=loki -n loki
Troubleshooting Common Issues
Pods Stuck in Pending State
This often indicates resource constraints:
kubectl describe pod -n loki <pod-name>
Look for events mentioning insufficient CPU, memory, or PVC issues.
Configuration Errors
If Loki fails to start, check the configuration:
kubectl logs -n loki loki-0 -c loki
Persistence Issues
If using persistent storage:
kubectl get pvc -n loki
Ensure PVCs are in the "Bound" state.
Summary
In this guide, we've learned how to:
- Add the Grafana Helm repository
- Create a custom values file for Loki configuration
- Install Loki using Helm charts
- Verify the installation and access Loki
- Connect Grafana to our Loki instance
- Customize, upgrade, and troubleshoot the deployment
Helm charts provide a flexible and powerful way to deploy Grafana Loki on Kubernetes clusters. While we've covered the basics here, the charts offer extensive customization options to meet the needs of production environments.
Additional Resources
- Official Loki Helm Chart Documentation
- Grafana Loki Configuration Reference
- Helm Charts Best Practices
Exercises
- Install Loki with Promtail and Grafana in a single Helm release using the
loki-stack
chart - Modify your values file to enable the distributed mode for Loki
- Configure Loki to use a different storage provider (like GCS or Azure Blob Storage)
- Set up multi-tenancy in your Loki installation
- Create a Kubernetes CronJob to back up Loki's index and storage
If you spot any mistakes on this website, please let me know at [email protected]. I’d greatly appreciate your feedback! :)