avataroleksii_y

Summary

The provided web content is a tutorial on setting up Grafana Loki for log aggregation and visualization within a Kubernetes environment using Minikube.

Abstract

The article titled "Collect and View Logs with Grafana Loki" provides a step-by-step guide to deploying a logging stack using Grafana Loki, a cost-effective and easy-to-operate log aggregation system inspired by Prometheus. It emphasizes Loki's approach to log management, which avoids full-text indexing in favor of label-based indexing, making it more efficient and less expensive. The tutorial outlines the three main components of a Loki-based logging stack: Promtail for log collection, Loki for log storage and query processing, and Grafana for log visualization. The article walks readers through the deployment of Grafana and Loki on a Kubernetes cluster managed by Minikube, configuring Loki as a data source in Grafana, and demonstrates how to explore and query logs within the Grafana interface. The guide also covers the use of Helm for Loki deployment and provides screenshots for visual assistance throughout the process.

Opinions

  • The author positions Loki as a superior alternative to other log aggregation systems due to its simplicity, cost-effectiveness, and compatibility with Prometheus labeling conventions.
  • Loki is presented as particularly well-suited for Kubernetes environments, as it can automatically scrape and index Kubernetes Pod metadata.
  • The use of Helm for deploying Loki is recommended, indicating a preference for Helm's package management capabilities within the Kubernetes ecosystem.
  • The article suggests that using Grafana with Loki provides a seamless experience for users who are already familiar with Prometheus, as it allows for the integration of metrics and logs using the same label sets.
  • The inclusion of specific commands, code snippets, and screenshots conveys the author's commitment to providing a comprehensive and user-friendly tutorial experience.

Collect and View Logs with Grafana Loki

No war in Ukraine. Stop Russia!

Loki logo

Preface.

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.

In this article, we will install Grafana, Loki and collect logs from another container using Minikube.

Step 1. Grafana Deployment

Download configs for installing Grafana in Kubernetes from the tutorial git repository:

$ git clone https://[email protected]/oleksii_y/tutorial-grafana-loki.git

Go tutorial-Grafana-Loki folder to apply configs:

$ cd tutorial-Grafana-Loki && kubectl apply -f grafana

You should see something like this:

When grafana deployment will be ready

add this line to your hosts:

192.168.99.100 grafana.local

192.168.99.100 is Minikube IP

$ minikube ip
192.168.99.100

Now you can type grafana.local in your browser and access Grafana (default username and password is admin/admin)

Grafana

Step 2. Loki Deployment

Make sure you have the helm configure on your cluster:

$ helm init

Clone grafana/loki repository and navigate to production helm directory:

git clone https://github.com/grafana/loki.git && cd loki/production/helm

Deploy Loki and Promtail to your cluster:

helm install . -n loki --namespace <YOUR-NAMESPACE>
Helm install Loki output

3. Add Loki as Data Source in Grafana

Click the gear icon and go to Configuration.

Press Add data source button.

Add data source

Then choose Loki.

Choose data source type

Add as the URL http://loki:3100 and press Save & Test

Loki configured

Click Explore icon

Explore

Check existing logs, just open Log labels:

Let's look all stderr:

stderr

You can find all necessary files here

Thank you for reading!

Docker
Kubernetes
Grafana
Loki
Logs
Recommended from ReadMedium