Add kubernetes metadata to fluentd/fluent bit sidecar

<filter kubernetes.var.log.containers.**.log>
@type kubernetes_metadata
</filter>
  • Add environment variables in your fluentd or fluent-bit container yaml
- name: fluentd-sidecar
image: ..../fluentd...
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_LABELS
valueFrom:
fieldRef:
fieldPath: metadata.labels['app']
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
  • Retrieve environment variables in your fluentd configmap
<filter kubernetes.** >
@type record_transformer
<record>
NODE_NAME "#{ENV['NODE_NAME']}"
</record>
<record>
POD_NAMESPACE "#{ENV['POD_NAMESPACE']}"
</record>
<record>
POD_NAME "#{ENV['POD_NAME']}"
</record>
</filter>
  • Or, retrieve environment variables in your fluent-bit configmap
[FILTER]
Name modify
Match *
Add POD_NAME ${POD_NAME}
Add POD_NAMESPACE ${POD_NAMESPACE}
Add NODE_NAME ${NODE_NAME}

--

--

--

Data Engineer from Taiwan, recently working on EFK and Kubernetes projects.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

“Hybrid Apps are slow”

What is C-Programming

An Overview of Selenium and Automation Testing

Why you should think about functional programming

3G Pitch MUGA Flooring in Gunstone #3G #Pitch #MUGA #Flooring #Gunstone https://t.co/MyHiAeSYSL

Farida‘s — Week 5 : KUMA’s NLP Platform, Dialogflow vs Kata.ai?

How I went from newbie to Software Engineer in 9 months while working full time

Interfacing HC-RS04 Ultrasonic Sensor with Arduino

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jasmine H

Jasmine H

Data Engineer from Taiwan, recently working on EFK and Kubernetes projects.

More from Medium

Ansible Role to Configure K8S Multi Node Cluster over AWS Cloud.

Kubernetes Day-2 Operations — Part III: Network & Traffic Management, Auto Scaling, Associating…

From dev to admin: an easy Kubernetes privilege escalation you should be aware of — the defense

Kubernetes Hardening Tutorial Part 1: Pods