如何在kubernetes中的fluentd kubernete守护进程集中添加多个输出



我使用的是fluentd守护进程集docker映像,并通过fluentd将日志发送到ES,通过使用以下代码片段可以完美地工作:

containers:
- name: fluentd
image: fluent/fluentd-kubernetes-daemonset:v1.4.2-debian-elasticsearch-1.1
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: "my-aws-es-endpoint"
- name: FLUENT_ELASTICSEARCH_PORT
value: "443"
- name: FLUENT_ELASTICSEARCH_SCHEME
value: "https"
- name: FLUENT_ELASTICSEARCH_USER
value: null
- name: FLUENT_ELASTICSEARCH_PASSWORD
value: null

但问题是对于DR/HA,我们也要将日志保存到S3中。我的问题是,我们是否可以在kubernetes中的fluentd kubernete守护进程集中添加多个输出,如S3、Kinesis等?

如何将Fluentd部署到集群是主观的。你使用像Helm或Skafold这样的模板引擎吗?

如果是这样的话,它们内部应该有一个configmap/configuration选项来定制部署并提供自己的输入。例如,Helm fluentd可以通过在此处添加输出来定义:

https://github.com/helm/charts/blob/master/stable/fluentd/values.yaml#L97

这应该允许您制作多个流,以便将流动的数据输出到多个位置。

我注意到,在您提供的特定Docker Image中,它们有一些Ruby模板化的项目。该配置特别允许您将卷装载到fluentd文件夹中的conf.d/:https://github.com/fluent/fluentd-kubernetes-daemonset/blob/master/templates/conf/fluent.conf.erb#L9

也许是/etc/fluentd,但我建议在本地运行映像并自己检查。

只要您的配置文件以.conf结尾,您就可以添加任何您想要的内容。

如第一个答案中所述,您需要覆盖整个配置。您正在寻找输出类型";复制":

<match **>
@type copy
<store>
@type elasticsearch
...
</store>
<store>
@type s3
...
</store>
<store>
@type kinesis_streams
...
</store>
</match>

提示:因为每个<store>都很长,所以存储数量越大,它的可读性就越差。我通常用标签包装每个商店以增加可读性:

<match **>
@type copy
<store>
@type relabel
@label @es
</store>
<store>
@type relabel
@label @s3
</store>
<store>
@type relabel
@label @stream
</store>
</match>
<label @es>
<match **>
@type elasticsearch
...
</match>
</label>
<label @s3>
<match **>
@type s3
...
</match>
</label>
<label @stream>
<match **>
@type kinesis_streams
...
</match>
</label>

现在,您可以将标签移动到单独的配置文件中。除了可读性之外,它还有更多的好处:

  • 每个标签都是fluentd内部的独立事件流,因此它可以实现一组单独的过滤器,而不会影响其他标签。当你想过滤你要发送到不同商店的内容时,这是非常有用的,例如,只有INFO要流式传输,所有级别都要ES
  • 标签是可重复使用的,您可以从多个地方调用它。假设您有两个来源-将两者发送到同一标签

最新更新