Skip to main content
It’s 2 in the morning. Bob is in Kibana because something went wrong with logins. He searches for locked accounts and finds the line straight away: User 5 failed to log in, account locked. Good. But which pod generated that line? Was it production, or a test cluster someone forgot to switch on?
A dark-themed diagram titled "Two in the Morning" showing a sad user labeled "Bob" on the left and a production server with a smiling robot and a message bubble reading "USER5 failed to log in, account locked." A blank "test" server appears to the right, with the caption "Which copy?" below.
Bob opens the stored record and inspects what’s actually indexed. There is a timestamp, a stream name, and the message — that’s it. Everything Bob needs to answer “which environment, which team, which pod?” existed on the node briefly, but none of that contextual metadata made the trip into Elasticsearch.
Why is the context missing? Because Fluentd only stores what it’s explicitly told to store. Fluentd reads the line from the node, parses it into fields, and forwards those fields. If you want extra metadata to accompany each log (for example team, environment, or pod information), something in the pipeline must enrich the record before it is indexed.
A diagram titled "Fluentd Stores What It's Told" showing a node (node01) sending data to Fluentd, which forwards it to Elasticsearch and then to a user labeled "Bob." Tags like "team," "time," "stream," and "log" are shown above the flow.

Enrich logs with Fluentd filters

What can sit in the middle of Fluentd’s pipeline and change a record on its way past? The answer is the filter section of Fluentd’s configuration — often treated as optional, but essential for log enrichment. A filter is a processing step between input and output that can modify each record: adding fields, rewriting values, or dropping records entirely. Fluentd ships with many built-in filters, but when none of them matches your needs you can write a custom Fluentd plugin. A plugin is a small Ruby file that Fluentd loads at startup to perform one job. A custom filter plugin typically:
  • inspects each record,
  • mutates or adds fields (for example environment or team),
  • returns the modified record for the rest of the pipeline.
A dark teal slide titled "A Step in the Middle" with a simple blue outline icon of a person-like figure standing on a platform centered above a horizontal slider labeled "Read", "Filter", and "Send." To the right of the platform are tag-like buttons reading "record", "time", "stream", "log", and "team", and a small KodeKloud logo sits in the bottom-left.
Picture logs sliding under a stamp and coming out labeled with environment: production. If a built-in Fluentd filter won’t do the job, write a small plugin file, drop it into a folder Fluentd can read, add a <filter> stanza to fluent.conf, and restart Fluentd so it loads the plugin. Example minimal filter stanza in fluent.conf:
This technique — adding metadata to logs at collection time — is called log enrichment. Enriching logs at the collector is necessary because once data is indexed in Elasticsearch, adding the missing original context is impractical.

Index lifecycle: stop the disk from filling up

Every day Fluentd typically creates a new index (for example fluentd-2026.10.13). If indices are never removed, disk usage grows until a node runs out of space.
A dark-themed infographic titled "One New Index Every Day" showing a Fluentd logo sending data (dotted arrow) to an index labeled "fluentd-2026.10.13" above a row of cylindrical database/storage icons. A small KodeKloud logo is visible in the bottom-left.
If Bob deletes old indices only when he remembers, there will be a Friday where he forgets — and Elasticsearch runs out of disk space.
An infographic titled "The Friday He Forgets" showing several cylindrical disk icons with blue fill levels and one highlighted at 100% labeled "Disk." A sad user icon labeled "Bob" and a crossed-out "Friday" calendar suggest the disk became full because he forgot Friday.
Instead of manual cleanup, encode retention and rollover behavior into Elasticsearch using Index Lifecycle Management (ILM). The typical policy for logs:
  • while an index is being written it is in the hot phase,
  • when it reaches a size threshold (e.g. 5 GB) or age threshold (e.g. 30 days) it is rolled over to a new index,
  • after a longer retention period (e.g. 90 days) the retired index is deleted.
Two core concepts:
  • rollover: switch from an actively-written index to a new one when size/age limits are hit,
  • lifecycle policy: rules that automatically move indices through hot → delete (and other) phases.
To summarize the operational rules:

Lab: build a custom filter and an ILM policy

Two practical goals:
  1. Create a simple custom Fluentd filter plugin (my_custom_filter) that adds environment and team fields.
  2. Create an Elasticsearch ILM policy and template so Fluentd indices rollover at 5 GB or 30 days and are deleted after 90 days.
After adding or changing a Fluentd plugin file, restart the Fluentd process (or pod) so it loads the new plugin. Place plugin files in a directory mounted into the Fluentd container (for example, /fluentd/plugins) and ensure Fluentd’s config or startup includes that directory.

1) Create a simple custom Fluentd filter plugin (Ruby)

Place a file named my_custom_filter.rb into Fluentd’s plugins directory. This example adds environment and team fields based on the record’s hostname or Kubernetes labels. Customize the detection logic for your environment.
Enable the filter in your fluent.conf:
Restart Fluentd (or the Fluentd DaemonSet/Pod) so it picks up the new plugin and configuration. After this, records arriving in Elasticsearch should include the extra fields and Bob can determine which environment or team produced the log.

2) Create an Index Lifecycle Management (ILM) policy in Elasticsearch

This ILM policy rolls indices over when they reach 5 GB or 30 days and deletes indices older than 90 days.

3) Create an index template that attaches the ILM policy and sets a rollover alias

Use a composable index template (recommended on modern Elasticsearch versions). This template:
  • matches indices named fluentd-*,
  • applies the ILM policy fluentd_policy,
  • configures the rollover alias fluentd-write.

4) Create the initial write index with the alias so rollover can occur

Rollover requires an initial index that is write-enabled for the alias. Create fluentd-000001 and attach the alias fluentd-write:

5) Configure Fluentd to write to the alias

Ensure Fluentd’s Elasticsearch output writes to the rollover alias. This enables Elasticsearch to switch the write target when the ILM rollover condition is met. Example Fluentd output configuration (plugin parameters may vary by plugin version — consult the plugin docs):
(See Fluentd Elasticsearch plugin docs for the exact parameter names: https://docs.fluentd.org/output/elasticsearch)

Sample enriched record arriving in Elasticsearch

After the plugin runs, records should include additional fields:
With this configuration:
  • Fluentd enriches logs before they are indexed.
  • Elasticsearch automatically rolls over and deletes indices per the ILM policy, preventing unexpected disk growth.
Test your filter plugin and ILM policy in a staging environment first. Use smaller max_size/max_age values to validate rollover behavior and confirm enrichment by inspecting sample records in Kibana before rolling changes to production.

Two rules to remember

With log enrichment at collection time and automated index lifecycle management, Bob can reliably answer “which pod produced this?” and stop worrying about disks filling up on forgotten Fridays.

Watch Video