请教个关于 k8s 日志采集的问题

192 天前
 wtfedc

看到 filebeat 的样例用的是 /var/log/containers/*.log,里边通过软链接指向 /var/log/pods 对应的日志文件,是 k8s 为 pod 设置的日志目录,只有 1 个 rotate 后最新的日志。

而 containerd 的日志目录在 /var/lib/container/log,里边有所有的 rotation 前后的日志。

有个疑惑,如果采集 /var/log/containers/*.log,那日志轮转时候,filebeat 还没采集完,岂不是会丢失日志。

993 次点击
所在节点    Kubernetes
5 条回复
fengxsong
192 天前
filbeat 持有 file description ,rotate 的时候会变成 .deleted 状态。
GeekGao
192 天前
当 Kubernetes 中的 Pod 进行日志轮转时,它会创建一个新的日志文件,更新软链接指向新的日志文件,而旧的日志文件仍然保留在磁盘上直到被清理。
在这个过程中,即使 Filebeat 还没有读取完旧的日志文件,它也能通过 inode 继续读取直到读取完毕,不会丢失日志。
julyclyde
192 天前
所以其实这个问题是 filebeat 的问题,不是 k8s 的问题

https://www.elastic.co/guide/en/beats/filebeat/current/how-filebeat-works.html
For each input, Filebeat keeps a state of each file it finds. Because files can be renamed or moved, the filename and path are not enough to identify a file. For each file, Filebeat stores unique identifiers to detect whether a file was harvested previously.
wtfedc
192 天前
@GeekGao 一语点醒我梦中人,多谢
dorothyREN
191 天前
如果日志系统是 graylog 的话 docker 是支持直接用 gelf 协议 直接把日志干进去 es 的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/987848

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX