|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Installing Grafana Loki with Helm on Kubernetes" |
| 4 | +date: 2021-11-20 7:00:00 -0500 |
| 5 | +categories: kubernetes |
| 6 | +tags: homelab proxmox grafana logging promtail prometheus kubernetes helm |
| 7 | +--- |
| 8 | + |
| 9 | +In my previous video ([Meet Grafana LOKI, a log aggregation system for everything](https://img.youtube.com/vi/h_GGd7HfKQ8/0.jpg) and [post](https://techno-tim.github.io/posts/grafana-loki/), 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](https://www.youtube.com/watch?v=h_GGd7HfKQ8) |
| 10 | + |
| 11 | +## Installing helm |
| 12 | + |
| 13 | +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](https://helm.sh/docs/intro/install/) |
| 14 | + |
| 15 | +## Installing Loki Stack |
| 16 | + |
| 17 | +This command will: |
| 18 | + |
| 19 | +* install grafana |
| 20 | +* install prometheus |
| 21 | +* install loki |
| 22 | +* enable persistance for your stack and create a PVC |
| 23 | + |
| 24 | +```bash |
| 25 | +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 |
| 26 | +``` |
| 27 | + |
| 28 | +You'll want to set `loki.persistence.storageClassName=nfs-client` to your `StorageClass` |
| 29 | +In this example, I am using `nf-client` which is the [Kubernetes NFS Subdir External Provisioner](https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner) |
| 30 | + |
| 31 | +## Accessing the Grafana Dashboard |
| 32 | + |
| 33 | +To access your Grafana dashboard you can run |
| 34 | + |
| 35 | +```bash |
| 36 | +kubectl port-forward --namespace <YOUR-NAMESPACE> service/loki-grafana 3000:80 |
| 37 | +``` |
| 38 | + |
| 39 | +To get the password for the `admin` user run |
| 40 | + |
| 41 | +```bash |
| 42 | +kubectl get secret --namespace <YOUR-NAMESPACE> loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo |
| 43 | +``` |
| 44 | + |
| 45 | +This should print out your password |
| 46 | + |
| 47 | +You can now access your dashboard on `http://localhost:3000` |
| 48 | + |
| 49 | +## Ingress with Traefik |
| 50 | + |
| 51 | +If you want to create an `IngressRoute` and you are using traefik can you apply the following |
| 52 | + |
| 53 | +`ingress.yml` |
| 54 | + |
| 55 | +```yml |
| 56 | +apiVersion: traefik.containo.us/v1alpha1 |
| 57 | +kind: IngressRoute |
| 58 | +metadata: |
| 59 | + name: loki-grafana-ingress |
| 60 | + annotations: |
| 61 | + kubernetes.io/ingress.class: traefik-internal # change with your value |
| 62 | +spec: |
| 63 | + entryPoints: |
| 64 | + - websecure |
| 65 | + routes: |
| 66 | + - match: Host(`grafana.example.com`) # change with your value |
| 67 | + kind: Rule |
| 68 | + services: |
| 69 | + - name: loki-grafana |
| 70 | + port: 80 |
| 71 | +``` |
| 72 | +
|
| 73 | +```bash |
| 74 | +kubectl apply -f ingress.yml |
| 75 | +``` |
| 76 | + |
| 77 | +You should now be able to access your dashboard on `https://grafana.example.com` |
| 78 | + |
| 79 | +## LogQL sample queries |
| 80 | + |
| 81 | +Query all logs from the `container` label |
| 82 | + |
| 83 | +```sql |
| 84 | +{container="uptime-kuma"} |
| 85 | +``` |
| 86 | + |
| 87 | +query all logs from the `container` stream and filter on `error` |
| 88 | + |
| 89 | +```sql |
| 90 | +{container="uptime-kuma" |= "error"} |
| 91 | + |
| 92 | +``` |
| 93 | + |
| 94 | +query all logs from the `pod` label of `uptime-kuma-8d45g32fd-lk8rl` |
| 95 | + |
| 96 | +```sql |
| 97 | +{pod="uptime-kuma-8d45g32fd-lk8rl"} |
| 98 | + |
| 99 | +``` |
| 100 | + |
| 101 | +Read more about LogQL [here](https://grafana.com/docs/loki/latest/logql/) |
0 commit comments