apiVersion: apps/v1 kind: DaemonSet metadata: name: fluentd-gcp-v2.0 labels: k8s-app: fluentd-gcp kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile version: v2.0 spec: selector: matchLabels: k8s-app: fluentd-gcp kubernetes.io/cluster-service: "true" version: v2.0 updateStrategy: type: RollingUpdate template: metadata: labels: k8s-app: fluentd-gcp kubernetes.io/cluster-service: "true" version: v2.0 # 如果节点支持基于关键 Pod 注解的优先级方案, # 此注解可确保 fluentd 不会被驱逐。 # 请注意,此注解并不保证在这些节点上准入 (#40573)。 annotations: scheduler.alpha.kubernetes.io/critical-pod: '' spec: dnsPolicy: Default containers: - name: fluentd-gcp image: registry.k8s.io/fluentd-gcp:2.0.2 # 如果 fluentd 消耗它自己的日志,则可能出现以下情形: # fluentd 将一个块发送到服务器时失败 => 将其写入到日志 => # 尝试将此消息发送到该服务器 => 发送一个块时失败等等。 # 写入一个未导出到后端的文件,可以避免发生这类事情。 # 它还默认允许增加 fluentd 的详细程度。 command: - '/bin/sh' - '-c' - '/run.sh $FLUENTD_ARGS 2>&1 >>/var/log/fluentd.log' env: - name: FLUENTD_ARGS value: --no-supervisor resources: limits: memory: 300Mi requests: cpu: 100m memory: 200Mi volumeMounts: - name: varlog mountPath: /var/log - name: varlibdockercontainers mountPath: /var/lib/docker/containers readOnly: true - name: libsystemddir mountPath: /host/lib readOnly: true - name: config-volume mountPath: /etc/fluent/config.d # 存活探针旨在帮助处理 fluentd 无明显原因就静默挂起的情况, # 这种情况通常只能手动重启。这个探针的思路是: # 如果 fluentd 有 5 分钟未执行队列操作或未清洗数据分块, # 那么肯定出现了什么问题。 # 如果你要更改 fluentd 配置以减少 fluentd 收集的日志量, # 请考虑更改阈值或彻底关闭存活探针。 livenessProbe: initialDelaySeconds: 600 periodSeconds: 60 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; LAST_MODIFIED_DATE=`stat /var/log/fluentd-buffers | grep Modify | sed -r "s/Modify: (.*)/\1/"`; LAST_MODIFIED_TIMESTAMP=`date -d "$LAST_MODIFIED_DATE" +%s`; if [ `date +%s` -gt `expr $LAST_MODIFIED_TIMESTAMP + $STUCK_THRESHOLD_SECONDS` ]; then rm -rf /var/log/fluentd-buffers; exit 1; fi; if [ `date +%s` -gt `expr $LAST_MODIFIED_TIMESTAMP + $LIVENESS_THRESHOLD_SECONDS` ]; then exit 1; fi; nodeSelector: beta.kubernetes.io/fluentd-ds-ready: "true" tolerations: - key: "node.alpha.kubernetes.io/ismaster" effect: "NoSchedule" terminationGracePeriodSeconds: 30 volumes: - name: varlog hostPath: path: /var/log - name: varlibdockercontainers hostPath: path: /var/lib/docker/containers - name: libsystemddir hostPath: path: /usr/lib64 - name: config-volume configMap: name: fluentd-gcp-config