Skip to content

logfwd Usage in v1.6.x and Earlier

This page is for deployments that still use the legacy instances annotation. For current versions, see the logfwd guide.

Enable the DataKit logfwdserver input and check that Pods can reach datakit_addr on port 9533. Set admission.datakit/logfwd.instances under spec.template.metadata.annotations in the Deployment. This annotation enables the sidecar and supplies its collection tasks as a JSON array encoded as a string.

[
    {
        "datakit_addr": "datakit-service.datakit.svc:9533",
        "loggings": [
            {
                "logfiles": ["/var/log/app/*.log"],
                "ignore": [],
                "source": "app",
                "service": "checkout",
                "pipeline": "app.p",
                "character_encoding": "",
                "multiline_match": "^\\d{4}-\\d{2}-\\d{2}",
                "tags": {
                    "env": "production"
                }
            }
        ]
    }
]

Common fields:

Field Description
datakit_addr DataKit logfwdserver address
logfiles Array of absolute file paths; glob patterns are supported
ignore Array of file paths to exclude; glob patterns are supported
source Log source
service Service name; source is used when this is empty
pipeline Pipeline filename on DataKit
character_encoding Character encoding; usually left empty for automatic detection
multiline_match Regular expression for the first line of a multiline log; backslashes must be escaped in JSON
tags Tags added to logs

Deployment Example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: logging-demo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: logging-demo
  template:
    metadata:
      labels:
        app: logging-demo
      annotations:
        admission.datakit/logfwd.instances: '[{"datakit_addr":"datakit-service.datakit.svc:9533","loggings":[{"logfiles":["/var/log/app/*.log"],"source":"app"}]}]'
    spec:
      containers:
        - name: app
          image: busybox:1.36
          command: ["sh", "-c"]
          args:
            - mkdir -p /var/log/app; while true; do date >> /var/log/app/app.log; sleep 1; done

After creation, run:

kubectl get pod -l app=logging-demo -o jsonpath='{.items[0].spec.containers[*].name}'

The container list should include datakit-logfwd. Filter by source=app in the log explorer to see the example records. Recreate Pods after changing the annotation.

Feedback

Is this page helpful?