Skip to main content
Elasticsearch is running and answers on port 9200. It has its own storage, and at first glance Bob is proud of it.
A slide titled "Zero Hits" showing a smiling blue robot icon next to a cylindrical database/storage stack with a "9200" badge. On the right is a circular user avatar labeled "Bob" against a dark teal background.
Then Bob asks Elasticsearch for every document it holds — and the answer comes back empty: zero hits. Meanwhile, the app is busy on its node, writing line after line about what each user does on the website: “USER1 logged in”, “USER3 clicked X”, and so on. The logs exist — they’re just in the wrong place. So how do log lines from every node actually get into Elasticsearch? First, we need to see where those log lines sit right now.
A graphic titled "The Lines Are Elsewhere" showing glowing blue mascot/server icons on four platforms with document icons. Dotted arrows run from the three left nodes toward a larger node on the right next to a database.

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.
A dark-themed illustration titled "Where the Lines Sit" showing a small blue smiling container-like mascot standing on a floating platform with labels like "container runtime" and "USER1 logged in." The KodeKloud logo appears in the lower-left corner.

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.
An infographic titled "A Copy Script Breaks" on a dark teal background showing a smiling blue bot on a platform with documents, a "copy script" label, and icons for a user named Bob and a database. The word "Wednesday" appears near the bottom.

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.
An illustration titled "What Fluentd Does" showing two smiling blue agent icons exchanging a document (with a label "USER3") via an arrow. To the right is a cylinder labeled "Elasticsearch," implying log/document forwarding.

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).
A dark-themed diagram titled "A Deployment Won't Do" showing three server nodes labeled node01, node02, and node03 with dashed placeholders above them and two small blue smiling container/robot icons floating overhead. The word "Deployment" appears below the nodes.
Because Fluentd runs inside a container, the DaemonSet typically mounts the host’s log directories into the Pod. Common mounts include /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.
Example volume mounts for a Fluentd container:

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:
Example Fluentd source that tails container logs and parses them with a regular expression:
After parsing, records flow through optional filters (to add Kubernetes metadata, drop noise, or enrich logs). The 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 to pods 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.
An infographic titled "Permission to Read" showing an RBAC diagram with icons for sa (service account), c.role, api, pod, and ns connected by a dashed arrow. A small blue mascot sits on a platform at left and the KodeKloud logo appears in the bottom corner.

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.
A diagram titled "Bob Stops Visiting Nodes" showing a user named Bob on the left, three smiling node icons on platforms across the bottom, and a stacked database labeled "USER1" on the right with document icons.
That is the design: run a Fluentd DaemonSet that mounts host logs, parses and enriches lines, forwards them to Elasticsearch, and uses minimal RBAC to read Kubernetes metadata.

Watch Video