[Kubernetes (K8S)] Helm install Grafana Loki to deploy a log aggregation system within Kubernetes (K8S)
Loki: like Prometheus, but for logs
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus. It is designed to be very cost effective and easy to operate. It does not index the contents of the logs, but rather a set of labels for each log stream.
Compared to other log aggregation systems, Loki:
-
does not do full text indexing on logs. By storing compressed, unstructured logs and only indexing metadata, Loki is simpler to operate and cheaper to run.
-
indexes and groups log streams using the same labels you’re already using with Prometheus, enabling you to seamlessly switch between metrics and logs using the same labels that you’re already using with Prometheus.
-
is an especially good fit for storing Kubernetes Pod logs. Metadata such as Pod labels is automatically scraped and indexed.
has native support in Grafana (needs Grafana v6.0).
A Loki-based logging stack consists of 3 components:
-
promtail is the agent, responsible for gathering logs and sending them to Loki.
-
loki is the main server, responsible for storing logs and processing queries.
-
Grafana for querying and displaying the logs.
Loki is like Prometheus, but for logs: we prefer a multidimensional label-based approach to indexing, and want a single-binary, easy to operate system with no dependencies. Loki differs from Prometheus by focusing on logs instead of metrics, and delivering logs via push, instead of pull.
This article is about how to use Helm to deploy Loki Stack (Loki, Promtail, Grafana, Prometheus) on Kubernetes (K8S).
Prerequisites
-
Kubernetes (K8S)
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.For more information about installing and using Kubernetes (K8s), see the Kubernetes (K8s) Docs.
-
Helm
Helm is the best way to find, share, and use software built for Kubernetes.For more information about installing and using Helm, see the Helm Docs.
Installation
Custom Values.yaml
Remember to replace nfs
with your prefer storage class name.
1 | # values.yaml |
Install by Helm
Helm install loki-stack into loki-stack namespace.
1 | crate namespace: |
See Helm release about loki-stack
1 | helm list --namespace loki-stack |
See pods about loki-stack.
1 | kubectl get pods -n loki-stack |
Run Loki behind HTTPS ingress
If Loki and Promtail are deployed on different clusters you can add an Ingress in front of Loki. By adding a certificate you create an HTTPS endpoint. For extra security you can also enable Basic Authentication on the Ingress.
Promtail enable HTTPS
In Promtail, set the following values to communicate using HTTPS and basic authentication:
1 | loki: |
Sample Helm template for Ingress:
An Ingress example for loki-stack.
1 | # Ingress.loki.yaml |
Then kubectl apply it.
1 | kubectl apply -f Ingress.loki.yaml |
An Ingress example for loki-stack-grafana.
1 | # Ingress.loki-stack-grafana.yaml |
Then kubectl apply it.
1 | kubectl apply -f Ingress.loki.yaml |
References
[1] Helm | Grafana Labs - https://grafana.com/docs/loki/latest/installation/helm/
[2] loki-stack 2.0.2 · helm/loki - https://artifacthub.io/packages/helm/loki/loki-stack
[3] grafana/loki: Like Prometheus, but for logs. - https://github.com/grafana/loki