apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: logging
  labels:
    k8s-app: fluentd
    component: logging-agent
spec:
  minReadySeconds: 10
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  selector:
    matchLabels:
      k8s-app: fluentd
  template:
    metadata:
      labels:
        k8s-app: fluentd
    spec:
      containers:
      - name: fluentd
        image: quay.io/coreos/fluentd-kubernetes:v0.12.33-cloudwatch
        imagePullPolicy: Always
        command: ["fluentd", "-c", "/fluentd/etc/fluentd.conf", "-p", "/fluentd/plugins"]
        env:
        - name: FLUENTD_CONFIG
          value: fluentd-standalone.conf
        - name: AWS_REGION
          value: $REGION
        - name: AWS_ACCESS_KEY
          value: $ACCESS_KEY
        - name: AWS_SECRET_KEY
          value: $SECRET_KEY
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 500m
            memory: 200Mi
        ports:
        - name: prom-metrics
          containerPort: 24231
          protocol: TCP
        - name: monitor-agent
          containerPort: 24220
          protocol: TCP
        - name: http-input
          containerPort: 9880
          protocol: TCP
        livenessProbe:
          httpGet:
            # Use percent encoding for query param.
            # The value is {"log": "health check"}.
            # the endpoint itself results in a new fluentd
            # tag 'fluentd.pod-healthcheck'
            path: /fluentd.pod.healthcheck?json=%7B%22log%22%3A+%22health+check%22%7D
            port: 9880
          initialDelaySeconds: 5
          timeoutSeconds: 1
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - name: fluentd-config
          mountPath: /fluentd/etc
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: fluentd-config
        configMap:
          name: "fluentd-config"
      terminationGracePeriodSeconds: 60
      serviceAccountName: fluentd
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
