apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: google-fluentd
  namespace: kube-system
  labels:
    k8s-app: google-fluentd
    version: v1
spec:
  selector:
    matchLabels:
      k8s-app: google-fluentd
      version: v1
  template:
    metadata:
      labels:
        k8s-app: google-fluentd
        version: v1
    spec:
      serviceAccount: google-fluentd
      serviceAccountName: google-fluentd
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: fluentd-gcp
        image: gcr.io/stackdriver-agents/stackdriver-logging-agent:0.6-1.6.0-1
        imagePullPolicy: IfNotPresent
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: STACKDRIVER_METADATA_AGENT_URL
          value: http://$(NODE_NAME):8799
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: "/etc/google/auth/google-application-credentials.json"
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - |
              LIVENESS_THRESHOLD_SECONDS=${LIVENESS_THRESHOLD_SECONDS:-300}; STUCK_THRESHOLD_SECONDS=${LIVENESS_THRESHOLD_SECONDS:-900}; if [ ! -e /var/log/fluentd-buffers ]; then
                exit 1;
              fi; touch -d "${STUCK_THRESHOLD_SECONDS} seconds ago" /tmp/marker-stuck; if [[ -z "$(find /var/log/fluentd-buffers -type f -newer /tmp/marker-stuck -print -quit)" ]]; then
                rm -rf /var/log/fluentd-buffers;
                exit 1;
              fi; touch -d "${LIVENESS_THRESHOLD_SECONDS} seconds ago" /tmp/marker-liveness; if [[ -z "$(find /var/log/fluentd-buffers -type f -newer /tmp/marker-liveness -print -quit)" ]]; then
                exit 1;
              fi;
          failureThreshold: 3
          initialDelaySeconds: 600
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            memory: 500Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - mountPath: /etc/google-fluentd/config.d
          name: volume-config
        - name: googleapplicationcredentials
          mountPath: /etc/google/auth
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
        name: varlibdockercontainers
      - name: volume-config
        configMap:
          defaultMode: 420
          name: google-fluentd-cm
      - name: googleapplicationcredentials
        secret:
          secretName: google-fluentd-secret
          items:
          - key: google-application-credentials.json
            path: google-application-credentials.json
