Home Installing Grafana Loki with Helm on Kubernetes
Post
Cancel

Installing Grafana Loki with Helm on Kubernetes

In my previous video (Meet Grafana LOKI, a log aggregation system for everything and post, I promised that I would also explain how to install Granfana Loki on Kubernetes using helm. If you’re looking to set this up in docker-compose, be sure to check out this video

Installing helm

Think of helm as a package manager for kubernetes. It’a an easy way to bundle and deploy config to kubernetes with versioning. If you need to install helm visit helm.sh

Installing Loki Stack

First add Loki’s chart repository to helm

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

Then update the chart repository

1
helm repo update

This command will:

  • install grafana
  • install prometheus
  • install loki
  • enable persistence for your stack and create a PVC
1
helm upgrade --install loki grafana/loki-stack  --set grafana.enabled=true,prometheus.enabled=true,prometheus.alertmanager.persistentVolume.enabled=false,prometheus.server.persistentVolume.enabled=false,loki.persistence.enabled=true,loki.persistence.storageClassName=nfs-client,loki.persistence.size=5Gi

You’ll want to set loki.persistence.storageClassName=nfs-client to your StorageClass
In this example, I am using nf-client which is the Kubernetes NFS Subdir External Provisioner

Accessing the Grafana Dashboard

To access your Grafana dashboard you can run

1
kubectl port-forward --namespace <YOUR-NAMESPACE> service/loki-grafana 3000:80

To get the password for the admin user run

1
kubectl get secret --namespace <YOUR-NAMESPACE> loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

This should print out your password

You can now access your dashboard on http://localhost:3000

Ingress with Traefik

If you want to create an IngressRoute and you are using traefik can you apply the following

ingress.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: loki-grafana-ingress
  annotations: 
    kubernetes.io/ingress.class: traefik-internal # change with your value
spec:
  entryPoints:
    - websecure
  routes:
    - match: Host(`grafana.example.com`) # change with your value
      kind: Rule
      services:
        - name: loki-grafana
          port: 80
1
kubectl apply -f ingress.yml

You should now be able to access your dashboard on https://grafana.example.com

LogQL sample queries

Query all logs from the container label

1
{container="uptime-kuma"} 

query all logs from the container stream and filter on error

1
2
{container="uptime-kuma"} |= "error"

query all logs from the pod label of uptime-kuma-8d45g32fd-lk8rl

1
2
{pod="uptime-kuma-8d45g32fd-lk8rl"}

Read more about LogQL here

Upgrading Loki Stack

To upgrade, you run the same command you use to install it, with an updated chart

1
helm repo update
1
helm upgrade --install loki grafana/loki-stack  --set grafana.enabled=true,prometheus.enabled=true,prometheus.alertmanager.persistentVolume.enabled=false,prometheus.server.persistentVolume.enabled=false,loki.persistence.enabled=true,loki.persistence.storageClassName=nfs-client,loki.persistence.size=5Gi

⚙️ See all the hardware I recommend at https://l.technotim.live/gear

🚀 Don’t forget to check out the 🚀Launchpad repo with all of the quick start source files

This post is licensed under CC BY 4.0 by the author.

Techno Tim HomeLab and NEW Server Room Tour! (Late 2021)

Meet Grafana LOKI, a Log Aggregation System for Everything