DEV Community

Gokul Skumar
Gokul Skumar

Posted on

Introduction to the Loki Stack: Lightweight Logging for Kubernetes

What is the Loki Stack?

Loki Stack is a lightweight, cloud‑native logging system built with the same design philosophy as Prometheus. It’s a great fit for Kubernetes environments because it keeps things simple, scalable, and cost‑effective — all of which matter a lot in modern DevOps workflows.

The Core Idea 💡

Unlike traditional logging tools that index the entire log content, Loki takes a smarter approach: it indexes only the metadata labels. Logs themselves are stored as compressed streams. This makes Loki far more efficient and cheaper to run compared to systems like Elasticsearch.

Key Components

1. Loki

The core engine. It handles log ingestion, storage, and querying. Components like the Distributor, Ingester, and Querier work together to push logs, compress them, store them (often in S3 or GCS), and make them searchable.

GitHub logo grafana / loki

Like Prometheus, but for logs.

Loki Logo

Check Go Report Card Slack Fuzzing Status

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…

2. Grafana

This is where you visualize and explore logs. Using LogQL, you can filter log streams and even correlate logs with metrics and traces in the same dashboard.

3. Promtail or Fluentd

These agents run on your nodes or containers. They collect logs, attach meaningful labels, and send them to Loki.

Architecture Diagram:


Architecture Diagram

Helm Chart Installation

First, add the Grafana repository and download the chart to your local machine:



helm repo add grafana https://grafana.github.io/helm-charts
helm fetch grafana/loki-stack
Next, install the chart into your cluster:

helm upgrade --install loki --namespace=loki-stack <path>
Accessing Grafana
If you are using the Grafana instance included in the Loki package, retrieve the admin password with this command:

kubectl get secret --namespace <namespace> loki-grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
Configuring the Loki Data Source
To connect Loki to your existing Grafana instance:

Click the Configuration (gear icon) in the left panel.
Select Data sources.
Click the Add data source button.
Select Loki from the list.
Set the URL to: http://loki.<namespace>.svc:3100.
Click Save & test.

Success! If configured correctly, you will see a green message: Data source connected and labels found.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)