【问题标题】:Kubernetes logging with fluentd daemonset使用 fluentd daemonset 进行 Kubernetes 日志记录
【发布时间】:2019-07-11 06:35:12
【问题描述】:

我在 kubernetes 集群中配置了 fluentd-daemonset 以将日志发送到 cloudwatch。我按照this 教程设置了fluentd。但是在 cloudwatch 中,我可以看到我也看到了 fluentd 的日志。如何停止将流利的日志推送到 cloudwatch?

这是我使用的配置文件,

<source>
  @type tail
  @id in_tail_container_logs
  @label @containers
  path /var/log/containers/*.log
  pos_file /var/log/fluentd-containers.log.pos
  tag *
  read_from_head true
  <parse>
    @type json
    time_format %Y-%m-%dT%H:%M:%S.%NZ
  </parse>
</source>

<label @containers>
  <filter **>
    @type kubernetes_metadata
    @id filter_kube_metadata
  </filter>

  <filter **>
    @type record_transformer
    @id filter_containers_stream_transformer
    <record>
      stream_name ${tag_parts[3]}
    </record>
  </filter>

  <match **>
    @type cloudwatch_logs
    @id out_cloudwatch_logs_containers
    region "#{ENV.fetch('REGION')}"
    log_group_name "/eks/#{ENV.fetch('CLUSTER_NAME')}/containers"
    log_stream_name_key stream_name
    remove_log_stream_name_key true
    auto_create_stream true
    retention_in_days "#{ENV.fetch('RETENTION_IN_DAYS')}"
    <buffer>
      flush_interval 5
      chunk_limit_size 2m
      queued_chunks_limit_size 32
      retry_forever true
    </buffer>
  </match>
</label>

【问题讨论】:

    标签: logging kubernetes amazon-cloudwatch fluentd


    【解决方案1】:

    我在配置中排除了带有exclude_path的fluentd日志,如下所示,现在我没有得到它们。

    <source>
      @type tail
      @id in_tail_container_logs
      @label @containers
      path /var/log/containers/*.log
      pos_file /var/log/fluentd-containers.log.pos
      exclude_path ["/var/log/containers/*fluentd*"]
      tag *
      read_from_head true
      <parse>
        @type json
        time_format %Y-%m-%dT%H:%M:%S.%NZ
      </parse>
    </source>
    

    【讨论】:

      【解决方案2】:

      fluent.** 已被弃用,我们可以使用此匹配注释来排除流利的日志:

          <match @FLUENT_LOG>
            @type null
          </match>
      

      【讨论】:

        【解决方案3】:

        它应该按照注释工作:

        <match fluent.**>
          @type null
        </match>
        

        例如对于这个设置:

        <match fluent.**>
          @type file
          path /var/log/internal/my-fluentd.log
          compress gzip
        </match>
        

        根据文档,您可以使用此配置排除这些日志:

        exclude_path ["/var/log/internal/*.gz"]
        

        【讨论】:

          猜你喜欢
          • 2023-03-18
          • 1970-01-01
          • 2018-12-08
          • 1970-01-01
          • 2016-06-29
          • 1970-01-01
          • 1970-01-01
          • 2021-02-02
          • 1970-01-01
          相关资源
          最近更新 更多