问题描述
我正在使用fluentd daemonset docker image,并通过使用以下代码段将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-kubernetes-daemonset中添加多个输出,例如S3,Kinesis等?
解决方法
这取决于您如何将Fluentd部署到群集。您使用的模板引擎是Helm还是Skaffold?
如果是这样,则它们内部应具有configmap /配置选项,以自定义部署并提供您自己的输入。例如,可以通过在此处添加输出来定义头盔流利度:
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
结尾,您就可以添加所需的任何内容。
如第一个答案中所述-您需要覆盖整个配置。 您正在寻找output type "copy":
<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>
现在,您可以将标签移动到单独的配置文件中。 除了可读性之外,它还有更多好处:
- 每个标签都是流利的内部独立事件流,因此它可以实现一组单独的过滤器,而不会影响其他标签。当您要过滤要发送到不同商店的内容时,这非常有用,例如只有INFO信息流,所有级别的信息流都流向ES。
- 标签可重复使用,您可以从多个地方调用它。假设您有两个来源-将两者都发送到同一标签。