问题描述
我的kubernetes启用了活动功能,并像这样登录应用程序:
kubectl logs -n example-namespace example-app node-app
::ffff:127.0.0.1 - - [17/Sep/2020:14:12:19 +0000] "GET /docs HTTP/1.1" 301 175
::ffff:127.0.0.1 - - [17/Sep/2020:14:13:19 +0000] "GET /docs/ HTTP/1.1" 200 3104
::192.168.0.1 - - [17/Sep/2020:14:13:19 +0000] "GET /home-page HTTP/1.1" 200 3104
::ffff:127.0.0.1 - - [17/Sep/2020:14:13:19 +0000] "GET /docs HTTP/1.1" 301 175
::ffff:127.0.0.1 - - [17/Sep/2020:14:13:22 +0000] "GET /docs/ HTTP/1.1" 200 3104
我使用fluentD将日志发送到ClowdWatch。 我的fluentD配置:
如何过滤只匹配fluentD
:: 192.168.0.1--[17 / Sep / 2020:14:13:19 +0000]“ GET / home-page HTTP / 1.1” 200 3104
忽略
:: ffff:127.0.0.1--[17 / Sep / 2020:14:13:19 +0000]“ GET / docs HTTP / 1.1” 301175
谢谢!
解决方法
经过研究,我找到了这个解决方案:
<match kubernetes.var.log.containers.**_kube-system_**>
@type null
</match>
还有这个
<filter **>
@type grep
exclude1 log docs
</filter>
参考:
https://github.com/fabric8io/fluent-plugin-kubernetes_metadata_filter/issues/91
https://docs.fluentd.org/filter/grep
编辑
或添加:
exclude_path ["/var/log/containers/cloudwatch-agent*","/var/log/containers/fluentd*","/var/log/containers/*istio*"]
此配置忽略模式为 istio 的源文件。