Skip to content

Commit d539686

Browse files
feat(post): Added Grafana Loki for Kubernetes
1 parent d7b30a4 commit d539686

File tree

2 files changed

+138
-8
lines changed

2 files changed

+138
-8
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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/)

_posts/2021-11-20-grafana-loki.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ tags: homelab proxmox grafana logging promtail prometheus
1010

1111
I've been on a quest to find a new logging system. I've use quite a few in the past, some open source, some proprietary, and some home grown, but recently I've decided to switch. I've switched to Grafana Loki for all of my logs for all of my systems - this includes machines, devices, docker systems and hosts, and my all of my kubernetes clusters. If you're thinking of using Grafana and are also looking for a fast way to log all of your systems, join me as we discuss and configure Grafana Loki.
1212

13-
1413
[Watch Video](https://www.youtube.com/watch?v=h_GGd7HfKQ8)
1514

1615
(see video description for links to gear, discord, and other ways to connect.)
@@ -74,7 +73,9 @@ services:
7473
- loki
7574
```
7675
77-
```
76+
## Loki Config
77+
78+
```bash
7879
touch nano loki/loki-config.yml
7980
```
8081

@@ -113,9 +114,10 @@ ruler:
113114
alertmanager_url: http://localhost:9093
114115
```
115116
117+
## Promtail Config
116118
117-
```
118-
touch nano promtail/loki-config.yml
119+
```bash
120+
touch nano promtail/promtail-config.yml
119121
```
120122

121123
`promtail-config.yml`
@@ -132,6 +134,7 @@ clients:
132134
- url: http://loki:3100/loki/api/v1/push
133135

134136
# local machine logs
137+
135138
scrape_configs:
136139
- job_name: local
137140
static_configs:
@@ -141,7 +144,8 @@ scrape_configs:
141144
job: varlogs
142145
__path__: /var/log/*log
143146

144-
## docker logs
147+
## docker logs
148+
145149
# scrape_configs:
146150
# - job_name: docker
147151
# pipeline_stages:
@@ -152,6 +156,7 @@ scrape_configs:
152156
# __path__: /var/lib/docker/containers/*/*-json.log
153157

154158
## syslog target
159+
155160
# scrape_configs:
156161
# - job_name: syslog
157162
# syslog:
@@ -165,9 +170,9 @@ scrape_configs:
165170
# target_label: 'host'
166171
```
167172

173+
## Loki Docker Driver
168174

169-
170-
```
175+
```bash
171176
sudo nano /etc/daemon.json
172177
```
173178

@@ -185,4 +190,28 @@ sudo nano /etc/daemon.json
185190

186191
```bash
187192
sudo systemctl restart docker
188-
```
193+
```
194+
195+
## LogQL sample queries
196+
197+
Query all logs from the `varlogs` stream
198+
199+
```sql
200+
{job="varlogs"}
201+
```
202+
203+
query all logs from the `varlogs` stream and filter on `docker`
204+
205+
```sql
206+
{job="varlogs" |= "docker"}
207+
208+
```
209+
210+
query all logs from the `container_name` label of `uptime-kuma` and filter on `host` of `juno`
211+
212+
```sql
213+
{container_name="uptime-kuma", host="juno"}
214+
215+
```
216+
217+
Read more about LogQL [here](https://grafana.com/docs/loki/latest/logql/)

0 commit comments

Comments
 (0)