Microservices Observability in a Kubernetes World: Logs
Shipping Container Logs with Promtail
Collecting metrics is essential, but logs are just as important. In a Kubernetes environment, logs are spread across many Pods and Nodes. Because Pods are short-lived—they appear, disappear, and move between Nodes as workloads scale—you need a specialized system to collect and aggregate them. Fortunately, when it comes to log management, the open-source and commercial ecosystems offer a true luxury of choice.
In this example, we are going to choose Promtail—an agent that collects logs from our cluster and can then send them to a tool like Loki, a log aggregation system designed to work with Grafana.
Promtail -> Loki -> Grafana: This trio forms a complete logging stack without much hassle.
ℹ️ Promtail functions similarly to Prometheus as it discovers targets by monitoring the Kubernetes API server. It performs label queries against the Kubernetes API at regular intervals to find Pods that match the label selectors. Once it has discovered the targets, it attaches to them and sends the contents of the logs to Loki.
There are multiple ways to install this tool — we will use Helm:
helm repo add grafana \
https://grafana.github.io/helm-charts
helm repo update
helm upgrade --install promtail grafana/promtail --namespace monitoring --version 6.17.0
You can verify that Promtail is running by executing the following command:
kubectl \Cloud-Native Microservices With Kubernetes - 2nd Edition
A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in KubernetesEnroll now to unlock all content and receive all future updates for free.
