gpt4 book ai didi

Kubernetes (GKE) 的日志记录解决方案

转载 作者:行者123 更新时间:2023-12-02 12:10:55 26 4
gpt4 key购买 nike

我正在寻找从 kubernetes 中的 pod 捕获日志以用于两个用例:

  • 实时 -> 我正在使用 kubectl logs ---现在
  • 非实时 -> 使用 stackdriver用管道传送到 bigquery

  • 对于这两个用例,一切正常,但是,当容器由于错误而提前退出时,我会丢失日志(即 stackdriver 没有足够快地获取它们)。
    这种延迟是否记录在某处?假设 stackdriver 不够快,是否还有另一种日志记录解决方案可以证明更有效?我正在考虑使用一个可捕获日志的 sidecar 容器,但我不确定这是否是最佳方法。

    最佳答案

    GKE 上的日志堆栈使用 fluentdstdout 中挑选日志, stderr那个container runtime writes to the nodes, as show in the node logging agent approach .
    这不是 much different来自您使用 kubectl logs 时所做的事情:

    When you run kubectl logs as in the basic logging example, the kubelet on the node handles the request and reads directly from the log file, returning the contents in the response.


    您发出 听起来 Stackdriver 不够快 但是,由于某种原因,您的容器运行时不会将日志写入上述日志文件,其中 fluentd 在导出之前选择日志。
    在更改日志架构之前,您可能需要 determine the reasons for pod failure甚至 customize the termination message path以便稍后使用 custom fluentd log collector 检索它.
    如果这不适合您的需求,您可以尝试 Elasticsearch反而。
    至于边车方法,虽然它是完全可行的,但 official documentation警告这种方法的一些缺点:

    Using a logging agent in a sidecar container can lead to significant resource consumption. Moreover, you won't be able to access those logs using kubectl logs command, because they are not controlled by the kubelet.


    最后,您还应该考虑到所有先前的信息都依赖于 的事实。容器进入创建阶段,可以写入日志文件 .如果您的容器有“提前退出”,这意味着 aren't even created ,那么日志可能一开始就没有,Stackdriver 永远不会选择它们。
    编辑:
    提到您还想考虑失败的容器需要写入两个输出, stdoutstderr .如果它“静默”地失败,也不会反射(reflect)在 Stackdriver 中。

    关于Kubernetes (GKE) 的日志记录解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63121898/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com