apiVersion: apps/v1
kind: DaemonSet

metadata:
  name: fluent
  namespace: monitoring
  labels:
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile

spec:
  selector:
    matchLabels:
      app: fluent

  template:
    metadata:
      labels:
        app: fluent
      # This annotation ensures that fluentd does not get evicted if the node
      # supports critical pod annotation based priority scheme.
      # Note that this does not guarantee admission on the nodes (#40573).
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
        seccomp.security.alpha.kubernetes.io/pod: 'docker/default'

    spec:
      serviceAccountName: fluent
      tolerations:
      # this toleration is to have the daemonset runnable on master nodes
      # remove it if your masters can't run pods
        - key: node-role.kubernetes.io/master
          effect: NoSchedule

      containers:
        - name: fluentd
          image: fluent/fluentd-kubernetes-daemonset:v1.10.4-debian-elasticsearch7-1.0
          env:
            - name:  FLUENT_ELASTICSEARCH_HOST
              value: "elasticsearch"
            - name:  FLUENT_ELASTICSEARCH_PORT
              value: "9200"
            - name: FLUENT_ELASTICSEARCH_SCHEME
              value: "http"
            # Option to configure elasticsearch plugin with self signed certs
            # ================================================================
            # - name: FLUENT_ELASTICSEARCH_SSL_VERIFY
            #   value: "true"
            # Option to configure elasticsearch plugin with tls
            # ================================================================
            # - name: FLUENT_ELASTICSEARCH_SSL_VERSION
            #   value: "TLSv1_2"
            # X-Pack Authentication
            # =====================
            - name: FLUENT_ELASTICSEARCH_USER
              value: "elastic"
            - name: FLUENT_ELASTICSEARCH_PASSWORD
              value: "changeme"
            # Logz.io Authentication
            # ======================
            # - name: LOGZIO_TOKEN
            #   value: "ThisIsASuperLongToken"
            # - name: LOGZIO_LOGTYPE
            #   value: "kubernetes"
          resources:
            requests:
              cpu: 50m
              memory: 100Mi
            limits:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - name: varlog
              mountPath: /var/log
            - name: varlibdockercontainers
              mountPath: /var/lib/docker/containers
              readOnly: true
            - name: fluent-config
              mountPath: /etc/fluent/config.d
      nodeSelector:
        beta.kubernetes.io/fluentd-ds-ready: "true"
      terminationGracePeriodSeconds: 30
      volumes:
        - name: varlog
          hostPath:
            path: /var/log
        - name: varlibdockercontainers
          hostPath:
            path: /var/lib/docker/containers
        - name: fluent-config
          configMap:
            name: fluent
