首页 > 解决方案 > Kubernetes - 保存 pod 的执行日志

问题描述

我正在尝试将容器的执行日志保留在 Kubernetes 中。

我在我的 cronjob yamlsuccessfulJobsHistoryLimit: 5 failedJobsHistoryLimit: 5中添加了以查看执行历史记录,但是当我尝试查看 pod 的日志时出现此错误

在此处输入图像描述

我认为这是因为 pod 已被删除,因为当我转到正在运行的 pod 时,我可以看到日志。

在此处输入图像描述

那么有没有办法将日志保存在 Kubernetes 的这一部分中,或者我必须设置一些东西才能拥有这个功能?

抱歉,如果有人问过这个问题,但我并没有真正找到任何东西,而且我是 Kubernetes 的新手。

感谢您的回复。

标签: kubernetesloggingkubernetes-pod

解决方案


Looking at this problem in a bigger picture it's generally a good idea to have your logs stored via logging agents or directly pushed into an external service as per the official documentation.

Taking advantage of Kubernetes logging architecture explained here you can also try to fetch the logs directly from the log-rotate files in the node hosting the pods. Please note that this option might depend on the specific Kubernetes implementation as log files might be deleted when the pod eviction is triggered.


推荐阅读