Skip to main content
Let’s start with the filter—order matters. Context (the stamp) must be added to each record before Elasticsearch stores it. The timestamp and any additional fields belong inside Fluentd, upstream of everything else.
A dark-themed diagram titled "The Stamp Belongs in Fluentd." It shows node01 sending data to Fluentd, which forwards to Elasticsearch, alongside a stamp labeled "USER5 context" and a user icon named Bob.
Filter and routing sections in Fluentd are processed top-to-bottom: sources read data in, filters transform records, and matches route them out. Place your filters between <source> and <match> so the additional context is present before data leaves Fluentd.
What does a custom filter look like in practice?
  • Bob creates a plugins folder next to his Fluentd configuration and adds one Ruby file.
  • Plugin files must be prefixed with filter_ so Fluentd discovers them when scanning plugin directories.
Commands to create the plugin file:
Example minimal filter plugin (filter_my_custom_filter.rb). It registers as my_custom_filter, exposes a string config parameter additional_data, and stamps each record in filter:
static_info is a placeholder. In production use cases set this to the environment name, owning team, node identifier, or another useful metadata value. Enabling the plugin in Fluentd’s configuration Fluentd will not use the plugin just because the file exists — you must reference it in fluent.conf and ensure the <filter> appears between a <source> and the <match> that sends data out. Example fluent.conf fragment (source → filter → match):
Order is critical. If you place <filter> after <match>, the lines have already been routed out and the filter will not be applied.
Expose the host plugin folder to the Fluentd container The plugin file lives on the host, but Fluentd runs in a container. Mount the host plugins folder into the Fluentd container so the runtime can load it. Bob edits the Fluentd DaemonSet YAML, adding a hostPath volume and corresponding volumeMount.
A dark-themed diagram titled "One More Gap" showing a blue mascot inside a dashed "container" on a node labeled "node01," separated from a nearby "plugins" box by a question-marked gap. A blank terminal window is drawn in the top-right.
DaemonSet snippet (showing volumeMounts and volumes):
Quick reference — mounts and host paths:
Using hostPath gives the container direct access to the node filesystem. Validate permissions and security implications before applying in production.
After updating and re-applying the DaemonSet, the Fluentd container will start with the plugins folder mounted and the custom filter available. What the filter produces When a log line passes through Fluentd after the filter is applied, records include the stamped metadata:
That completes the Fluentd side. Next, configure index lifecycle rules in Elasticsearch. Index Lifecycle Management (ILM) goes into Elasticsearch ILM policies live in Elasticsearch and control rollover and retention behavior. In this environment the Elasticsearch API is available on NodePort 30200.
A dark teal presentation slide titled "Rules Go Into Elasticsearch" showing several translucent cylindrical database icons across the bottom left. The Elasticsearch logo and label appear on the right with a small KodeKloud watermark in the lower-left corner.
Example ILM policy file (my_logs_policy.json): a hot phase with rollover at 5 GB or 30 days, and a delete phase at 90 days.
Push the policy to Elasticsearch and confirm the normalized settings:
A policy by itself does nothing until you associate it with indices.
A dark presentation slide titled "A Rulebook Nobody Picked Up" shows a small card labeled "my_logs_policy" listing "Rollover — 5 GB" and "Delete — 90 days," with a dashed arrow pointing to the right. A small KodeKloud logo appears in the bottom-left corner.
Create an index template with ILM settings and a rollover alias To attach the ILM policy automatically, create an index template (e.g., my_logs_template) that matches the index naming pattern Fluentd will create. The template names the ILM policy and sets a rollover alias such as my-logs. Fluentd writes to the alias while ILM rolls the underlying write indices. Diagram: one stable write alias
A diagram titled "One Stable Name" showing a Fluentd icon on the left and several cylindrical storage containers, with an arrow labeled "my-logs" pointing to a highlighted larger container. It illustrates consolidating logs under a single stable name.
Verify the template includes the lifecycle and rollover alias:
Search and answer questions in minutes With Fluentd stamping each record and Elasticsearch enforcing ILM, you can answer operational questions quickly without chasing ephemeral pods.
  • Open Kibana.
  • Set the time range (for example, last night).
  • Search for user5 (or your stamped field).
Every matching line from every node will be indexed and stamped with the originating node and configured metadata. Retention will be enforced automatically by the ILM policy. If load spiked and more Elasticsearch pods were required, the cluster can scale and rebalance; if JVM heap usage became critical, alerts would notify you before user impact grows.
A dark-themed dashboard titled "An Answer in Minutes" showing two server nodes (node01, node02) represented by smiling blue robot icons. A circular gauge reads "94% Heap" and there's a user avatar labeled "Bob" on the right.
Summary checklist Useful references He has the answer in minutes, and he sends it back with confidence.

Watch Video

Practice Lab