1. Installing with Helm #
A ready-to-use DaemonSet.
Commands #
helm repo add fluent https://fluent.github.io/helm-charts
helm upgrade --install fluent-bit fluent/fluent-bit -n logging --create-namespace -f values.yaml# values.yaml (extrait) : le chart accepte la configuration au format classique
config:
inputs: |
[INPUT]
Name tail
Path /var/log/containers/*.log
multiline.parser docker, cri
Tag kube.*
Mem_Buf_Limit 50MB
Skip_Long_Lines On
storage.type filesystem
filters: |
[FILTER]
Name kubernetes
Match kube.*
Merge_Log On
Keep_Log Off
K8S-Logging.Parser On
K8S-Logging.Exclude On
outputs: |
[OUTPUT]
Name loki
Match kube.*
Host loki-gateway.logging.svc
Port 80
Labels job=fluent-bit
Label_keys $kubernetes['namespace_name'],$kubernetes['container_name']Good practice:Merge_Log Onparses applications' JSON logs and puts their fields at the top level; thefluentbit.io/parserandfluentbit.io/excludeannotations let teams pick a parser or exclude their pods.
2. Multiline logs #
Java and Python stack traces.
multiline #
A Java exception spans 50 lines: without processing, each line becomes a record. The built-in multiline parsers (docker, cri, java, python, go) or custom ones group them:
[MULTILINE_PARSER]
name java_exceptions
type regex
flush_timeout 1000
rule "start_state" "/^\d{4}-\d{2}-\d{2} .*/" "cont"
rule "cont" "/^\s+at .*|^Caused by: .*/" "cont"
[FILTER]
name multiline
match kube.*
multiline.key_content log
multiline.parser java, java_exceptions3. Buffering and backpressure #
Lose nothing, saturate nothing.
Settings #
| Parameter | Effect |
|---|---|
mem_buf_limit | Memory cap for an input: beyond it, reading is paused (backpressure) |
storage.type filesystem | Pending chunks are written to disk and survive a restart |
storage.total_limit_size (output) | Maximum disk buffer size per destination |
retry_limit (output) | Number of retries (no_limits to retry indefinitely) |
Common mistake: With a memory-only buffer, a Loki outage of a few minutes can lose logs or pause reading. Enable the disk buffer on production nodes.
Monitoring Fluent Bit #
curl -s localhost:2020/api/v1/health
curl -s localhost:2020/api/v2/metrics/prometheus | grep -E 'fluentbit_(input_records|output_(proc_records|errors|retries_failed))_total'- alert: FluentBitOutputErrors
expr: sum by (name) (rate(fluentbit_output_retries_failed_total[5m])) > 0
for: 10m
labels: { severity: warning }