Browse docs
On this page

Fluent Bit on Kubernetes (sidecar)

Step-by-step guide to running Fluent Bit as a sidecar container next to your app pod and shipping its log file here with the built-in http output plugin.

This is the Kubernetes half of the Fluent Bit door. Everything about the destination is identical - Fluent Bit's built-in http output plugin, pointed at the same POST /v1/events endpoint, authenticated with the same ingest key. What changes is where Fluent Bit runs and how it gets hold of your application's log lines.

DaemonSet or sidecar?

Two topologies, and the right one depends on how your app emits logs.

DaemonSetSidecar
RunsOne Fluent Bit pod per nodeOne Fluent Bit container per app pod
Reads/var/log/containers/*.log (every pod on the node)A file on a volume shared with the app container
NeedsNode-level access, a ClusterRole, hostPath mountsNothing cluster-scoped
Good forEverything on the cluster, one configApps that write to a file rather than stdout, or a namespace you do not own node access in

A DaemonSet is the usual default: if your containers write to stdout/stderr, the kubelet already writes those streams to files on the node and one Fluent Bit per node picks up all of them. Use a sidecar when that is not true or not available: the app writes a log file (an access log, an audit log, a framework that will not be talked out of app.log), or you only have rights inside a single namespace and cannot mount hostPath or bind a ClusterRole.

The rest of this page is the sidecar. The trade to know up front: a sidecar costs a container's memory and CPU per pod rather than per node, so a hundred replicas means a hundred Fluent Bits.

Before you start

You need:

  • kubectl pointed at the cluster, and permission to create a Secret, ConfigMap and Deployment in your namespace.
  • An ingest key. Create one from Fluent Bit under View all in Connect Your Data: name what is sending the logs, and the wizard mints a key and shows a live watch for the first event. The key is shown once - we store only a hash of it - so put it straight into the Secret in step 1.
  • An app container that writes its logs to a file path you control. If yours only writes to stdout, prefer the DaemonSet topology instead: making an app write to a file just so a sidecar can read it is a step backwards.

Step 1: Put the ingest key in a Secret

The key is a credential, so it does not belong in the ConfigMap next to the rest of the config, and it certainly does not belong in a manifest in git:

Shell
kubectl create secret generic obistack-ingest \
  --namespace my-app \
  --from-literal=api-key='YOUR_INGEST_KEY'

If you manage secrets with External Secrets, Sealed Secrets, or your cloud provider's secret store, create it however you normally would - the only thing the rest of this guide assumes is a Secret called obistack-ingest with a key named api-key.

Step 2: Create the Fluent Bit ConfigMap

This is the config the sidecar mounts. It tails one file and ships every record it reads to us:

YAML
apiVersion: v1
kind: ConfigMap
metadata:
  name: fluent-bit-sidecar
  namespace: my-app
data:
  fluent-bit.conf: |
    [SERVICE]
        Flush           5
        Log_Level       info
        Daemon          off
        Parsers_File    parsers.conf

    [INPUT]
        Name            tail
        Path            /var/log/app/*.log
        Tag             app.logs
        DB              /var/log/app/flb.db
        Refresh_Interval 5
        Skip_Long_Lines  On

    [FILTER]
        Name            record_modifier
        Match           app.logs
        Record          k8s_pod    ${POD_NAME}
        Record          k8s_ns     ${POD_NAMESPACE}

    [OUTPUT]
        Name            http
        Match           app.logs
        Host            ingest.obistack.com
        Port            443
        URI             /v1/events
        Format          json
        tls             On
        tls.verify      On
        Header          Authorization Bearer ${LOGS_API_KEY}

Three things in there are doing real work:

  • Path and the shared volume have to agree. /var/log/app is the emptyDir both containers mount in step 3. The app writes into it, Fluent Bit reads out of it, and neither one knows about the other.
  • DB is the checkpoint file, and it has to live on that same volume. It is what stops a restarted sidecar re-shipping the whole file from byte zero. Note that an emptyDir dies with the pod, which is the correct scope here: a new pod has a new log file too.
  • ${LOGS_API_KEY}, ${POD_NAME} and ${POD_NAMESPACE} are environment variables, expanded by Fluent Bit at startup. They come from the Secret and the downward API in step 3, so the key is never written into the ConfigMap.

The same config in the 3.x YAML format, if that is what your Fluent Bit image is configured for (use fluent-bit.yaml as the data key and point the container at it):

YAML
service:
  flush: 5
  log_level: info

pipeline:
  inputs:
    - name: tail
      path: /var/log/app/*.log
      tag: app.logs
      db: /var/log/app/flb.db
      refresh_interval: 5
      skip_long_lines: on

  filters:
    - name: record_modifier
      match: app.logs
      records:
        - k8s_pod ${POD_NAME}
        - k8s_ns ${POD_NAMESPACE}

  outputs:
    - name: http
      match: app.logs
      host: ingest.obistack.com
      port: 443
      uri: /v1/events
      format: json
      tls: true
      tls.verify: true
      headers:
        Authorization: Bearer ${LOGS_API_KEY}

Step 3: Add the sidecar to your Deployment

The pattern is three parts: an emptyDir volume, an app container that writes into it, and a fluent-bit container that reads out of it.

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: my-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      volumes:
        - name: app-logs
          emptyDir: {}
        - name: fluent-bit-config
          configMap:
            name: fluent-bit-sidecar
      containers:
        # Your application, writing its log file into the shared volume.
        - name: app
          image: my-registry/my-app:1.4.2
          volumeMounts:
            - name: app-logs
              mountPath: /var/log/app

        # The sidecar, reading the same directory.
        - name: fluent-bit
          image: fluent/fluent-bit:3.1
          args: ["--config=/fluent-bit/etc/fluent-bit.conf"]
          env:
            - name: LOGS_API_KEY
              valueFrom:
                secretKeyRef:
                  name: obistack-ingest
                  key: api-key
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          volumeMounts:
            - name: app-logs
              mountPath: /var/log/app
              readOnly: true
            - name: fluent-bit-config
              mountPath: /fluent-bit/etc/
          resources:
            requests:
              cpu: 10m
              memory: 32Mi
            limits:
              memory: 128Mi

readOnly: true on the sidecar's mount is deliberate - Fluent Bit only ever reads your application's logs. It does mean the DB checkpoint file cannot be written to that path: either drop readOnly, or point DB at a second small emptyDir mounted read-write at, say, /var/flb. Pick one before you apply, or Fluent Bit will fail to open its database at startup and say so in its log.

Apply it:

Shell
kubectl apply -f fluent-bit-configmap.yaml
kubectl apply -f deployment.yaml
kubectl rollout status deployment/my-app -n my-app

Step 4: Confirm it worked

The sidecar logs what it is doing on startup, so read it first:

Shell
kubectl logs -n my-app deploy/my-app -c fluent-bit -f

A healthy start says [engine] started, names the http output plugin, and then goes quiet - Fluent Bit does not log successful deliveries at the default info level. Then watch Live Tail, or the Connect Your Data panel if you minted the key there: it polls for the first event and shows it as soon as it lands.

Debugging

Everything in the Fluent Bit page's debugging section applies here too - Tag/Match mismatches, a 401 from a bad key, TLS verification failures. What is specific to a sidecar:

  • Nothing in the file. Check the app container is genuinely writing to the mount path and not to stdout: kubectl exec -n my-app deploy/my-app -c app -- ls -l /var/log/app. An empty directory means the two volumeMounts do not agree, or the app's own log path is configured elsewhere.
  • Cannot open database at startup is the readOnly: true trade described above.
  • The pod restarts and you lose the tail position. Expected: an emptyDir and its checkpoint file are destroyed with the pod, along with the log file they tracked. Only worry about this if you are mounting a persistent volume instead.
  • The sidecar outlives the job, or dies before it. For a Job or CronJob, a plain sidecar container keeps the pod Running forever because Fluent Bit never exits. Kubernetes 1.29+ solves this properly with native sidecars (an initContainer with restartPolicy: Always) - move the fluent-bit container into initContainers with that field set and the kubelet will start it before the app and stop it after.
  • Logs stop under load. The tail input's default memory buffer is finite. Raise Mem_Buf_Limit, or enable filesystem buffering (storage.type filesystem in [SERVICE], backed by a writable volume) if the app can outrun the shipper in a burst.

Tenant Isolation & Data Boundaries

Identical to the Fluent Bit door: the workspace an event lands in is decided by the ingest key in the Authorization header and by nothing else. The record_modifier fields this guide adds (k8s_pod, k8s_ns) are ordinary event fields - they are searchable, and they cannot redirect an event into another workspace, in the same way a top-level tenant_id in a record body is dropped rather than honoured. Running one sidecar per pod does not widen that boundary: each one holds only the key it was given, mounted from a Secret in its own namespace. See Tenant Isolation for the full model.