---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat
  namespace: filebeat
  labels:
    app: filebeat
spec:
  selector:
    matchLabels:
      app: filebeat
  template:
    metadata:
      labels:
        app: filebeat
    spec:
      serviceAccountName: filebeat
      terminationGracePeriodSeconds: 30
      containers:
        - image: localhost:5000/klogs:latest-filebeat
          imagePullPolicy: Always
          name: filebeat
          args:
            - -c
            - /etc/filebeat.yml
            - -e
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: CLUSTER
              value: filebeat-clickhouse
          ports:
            - containerPort: 5066
              name: http
              protocol: TCP
          securityContext:
            runAsUser: 0
          resources:
            limits:
              cpu: 500m
              memory: 1024Mi
            requests:
              cpu: 250m
              memory: 512Mi
          volumeMounts:
            - mountPath: /var/log
              name: varlog
              readOnly: true
            - mountPath: /var/lib/docker/containers
              name: varlibdockercontainers
              readOnly: true
            - mountPath: /etc/filebeat.yml
              name: config
              readOnly: true
              subPath: filebeat.yml
            - mountPath: /usr/share/filebeat/data
              name: data
        - name: filebeat-exporter
          image: trustpilot/beat-exporter:0.4.0
          ports:
            - containerPort: 9479
              name: http-metrics
              protocol: TCP
          resources:
            limits:
              cpu: 25m
              memory: 32Mi
            requests:
              cpu: 25m
              memory: 32Mi
      tolerations:
        - effect: NoSchedule
          key: node-role.kubernetes.io/master
        - effect: NoExecute
          operator: Exists
      volumes:
        - name: varlog
          hostPath:
            path: /var/log
        - name: varlibdockercontainers
          hostPath:
            path: /var/lib/docker/containers
        - name: data
          hostPath:
            path: /var/lib/filebeat-data
            type: DirectoryOrCreate
        - name: config
          configMap:
            defaultMode: 0640
            name: filebeat
