V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wtfedc
V2EX  ›  Kubernetes

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

  •  
  •   wtfedc · 178 天前 · 975 次点击
    这是一个创建于 178 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    5 条回复    2023-11-02 21:49:39 +08:00
    fengxsong
        1
    fengxsong  
       178 天前
    filbeat 持有 file description ,rotate 的时候会变成 .deleted 状态。
    GeekGao
        2
    GeekGao  
       178 天前   ❤️ 1
    当 Kubernetes 中的 Pod 进行日志轮转时,它会创建一个新的日志文件,更新软链接指向新的日志文件,而旧的日志文件仍然保留在磁盘上直到被清理。
    在这个过程中,即使 Filebeat 还没有读取完旧的日志文件,它也能通过 inode 继续读取直到读取完毕,不会丢失日志。
    julyclyde
        3
    julyclyde  
       178 天前   ❤️ 1
    所以其实这个问题是 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
        4
    wtfedc  
    OP
       178 天前
    @GeekGao 一语点醒我梦中人,多谢
    dorothyREN
        5
    dorothyREN  
       178 天前
    如果日志系统是 graylog 的话 docker 是支持直接用 gelf 协议 直接把日志干进去 es 的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2948 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 14:42 · PVG 22:42 · LAX 07:42 · JFK 10:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.