9200. It has its own storage, and at first glance Bob is proud of it.


Where container logs live on a node
When a container prints a line, the container runtime writes it into a file on the node under/var/log/containers — one file per container. Kubernetes itself doesn’t aggregate those files for you. The app’s lines pile up in a file on whatever node the app happens to run on, and Elasticsearch does not go looking for them. Elasticsearch is a store — it only contains what somebody brings to it.

Why simple copy scripts fail
You could imagine Bob writing a script that copies the node’s log file into Elasticsearch every few minutes. That might work briefly, but it fails under normal cluster churn:- If the app gets rescheduled to another node, the script continues copying a file that stopped growing.
- If the team adds a new node, the script is not automatically present there — and new logs appear on that node.
- Ultimately, log lines are created on every node, so any collector needs to run on every node.

Enter Fluentd
Fluentd is a lightweight log collector that reads lines from one place, optionally normalizes or enriches them, and forwards them somewhere else (Elasticsearch in this case). The common pattern is to run Fluentd on every node, where it tails the node’s container log files and forwards new lines to Elasticsearch.
How to run one Fluentd on every node
A Deployment is not suitable here because it creates a fixed number of replicas and the scheduler may place them on the same node. What we need is exactly one Fluentd Pod per node — Kubernetes provides a DaemonSet for that use case. Describe the Fluentd Pod once in a DaemonSet and Kubernetes guarantees one Pod on each node (and schedules new Pods onto nodes that join the cluster).
/var/log and the container runtime’s log folder (for Docker: /var/lib/docker/containers). The runtime log folder should be mounted readOnly so Fluentd can read the logs but cannot modify them.
Note: container runtimes differ. For containerd or CRI-O the log locations and the exact files or symlinks under
/var/log may differ, so adjust the mounted paths to match your cluster’s runtime.What Fluentd does with each log line
Fluentd’s behavior is controlled by a configuration that typically contains these directive blocks:
A typical
source tails every container log file and parses each line. For example, a raw line might look like:
match block defines the output to Elasticsearch using Fluentd’s Elasticsearch output plugin:
Permissions: what Fluentd needs from Kubernetes
Fluentd often adds metadata (pod name, namespace, labels) by querying the Kubernetes API server. The API server requires authenticated requests, so Fluentd needs a service account and minimal RBAC permissions: typically read access topods and namespaces.
Grant Fluentd only the minimal RBAC permissions it needs — typically
get, list, and watch on pods and namespaces. Avoid granting broader cluster permissions than necessary.
Day-to-day result
Before Fluentd, finding last night’s error meant guessing which node ran the app, SSHing into it, and scanning a log file that might already be rotated or gone. With Fluentd running as a DaemonSet, log lines leave the node within seconds of being written and are indexed in Elasticsearch — Bob never needs to visit the node.
Links and references
- Kubernetes DaemonSet: https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/
- Fluentd documentation: https://docs.fluentd.org/
- Elasticsearch documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html