avatar

Bhuwan Upadhyay

Talks all about software engineering

Published on

Logging kubernetes using loki

Authors

Introduction

This article explains method of installing the helm chart loki-stack in kubernetes cluster. Also, it describes how to configure loki-stack with grafana dashboard to see loging from application that running in kubernetes cluster.

Prerequisites

Packages & Tools

Environment variables

export LOG_STORAGE_SIZE="5Gi"

Install Loki Stack

Add helm repository and update charts.

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

Below command is used to download values.yaml and replace with environment variables.

curl -o values.raw.yaml https://raw.githubusercontent.com/bhuwanupadhyay/kubernetes-lab/main/logging-kubernetes-using-loki/values.yaml && \
envsubst < "values.raw.yaml" > "values.out.yaml" && rm -rf values.raw.yaml

Install loki-stack chart.

helm upgrade --install --wait --timeout 600s loki grafana/loki-stack \
  --version 2.6.5 \
  --namespace monitoring --create-namespace \
  -f values.out.yaml

Port Forwarding

Visit here for how to port forward to access grafana dashboard.

App Deployment

curl -o foo.raw.yaml https://raw.githubusercontent.com/bhuwanupadhyay/kubernetes-lab/main/logging-kubernetes-using-loki/deployment.yaml && \
envsubst < "foo.raw.yaml" > "foo.out.yaml" && rm -rf foo.raw.yaml && \
kubectl apply -f foo.out.yaml

Explore Log Output

Image