使用 fluentd daemonset 进行 Kubernetes 日志记录
Kubernetes logging with fluentd daemonset
我在 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>
我在配置中排除了带有 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>
它应该按照注释工作:
<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"]
fluent.**
已被弃用,我们可以使用此匹配注释来排除流利的日志:
<match @FLUENT_LOG>
@type null
</match>
我在 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>
我在配置中排除了带有 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>
它应该按照注释工作:
<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"]
fluent.**
已被弃用,我们可以使用此匹配注释来排除流利的日志:
<match @FLUENT_LOG>
@type null
</match>