apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat
  labels:
    app: filebeat
spec:
  selector:
    matchLabels:
      app: filebeat
  template:
    metadata:
      labels:
        app: filebeat
    spec:
      serviceAccountName: filebeat
      containers:
      - name: filebeat
        image: yishuida/filebeat-oss:7.2.0
        args: [
          "-c", "/etc/filebeat.yaml",
          "-e"
        ]
        securityContext:
          runAsUser: 0
        env:
        - name: ES_HOST
          value: "elasticsearch"
        - name: ES_PORT
          value: "9200"
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
        # 将指定 volumes mount 到容器内的路径
        volumeMounts:
        - name: config
          mountPath: "/etc/filebeat.yaml"
          readOnly: true
          subPath: "filebeat.yaml"
        - name: varlibcontainers
          mountPath: /usr/share/filebeat/logs
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - name: varlogcontainers
          mountPath: /var/log/containers
        - name: varlogpods
          mountPath: /var/log/pods
      # 创建 volumes
      volumes:
      - name: config
        configMap:
          defaultMode: 0644
          name: filebeat-config
      # data folder stores a registry of read status for all files, so we don't send everything again on a Filebeat pod restart
      - name: data
        hostPath:
          path: /var/lib/filebeat-data
          type: DirectoryOrCreate
      - name: logs
        hostPath:
          path: /var/lib/filebeat-logs
          type: DirectoryOrCreate
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: varlibcontainers
        hostPath:
          path: /var/lib/containers
      - name: varlogpods
        hostPath:
          path: /var/log/pods
      - name: varlogcontainers
        hostPath:
          path: /var/log/containers
