如何查看已终止 Pod 的日志 [英] How to see logs of terminated pods

查看:39
本文介绍了如何查看已终止 Pod 的日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 selenium hubs 并且我的 pod 经常被终止.我想查看终止的 pod 的日志.怎么做?

I am running selenium hubs and my pods are getting terminated frequently. I would like to look at the logs of the pods which are terminated. How to do it?

NAME                                               READY     STATUS              RESTARTS   AGE
chrome-75-0-0e5d3b3d-3580-49d1-bc25-3296fdb52666   0/2       Terminating         0          49s
chrome-75-0-29bea6df-1b1a-458c-ad10-701fe44bb478   0/2       Terminating         0          23s
chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5   0/2       ContainerCreating   0          7s

kubectl logs chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5
Error from server (NotFound): pods "chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5" not found
$ kubectl logs chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5 --previous
Error from server (NotFound): pods "chrome-75-0-8929d8c8-1f7b-4eba-96f2-918f7a0d77f5" not found

推荐答案

运行 kubectl logs -p 将在 API 级别从现有资源中获取日志.这意味着使用此命令终止的 Pod 的日志将不可用.

Running kubectl logs -p will fetch logs from existing resources at API level. This means that terminated pods' logs will be unavailable using this command.

正如其他答案中提到的,最好的方法是通过 记录代理或直接将这些日志推送到外部服务.

As mentioned in other answers, the best way is to have your logs centralized via logging agents or directly pushing these logs into an external service.

或者,鉴于 日志架构Kubernetes,您或许可以获取日志直接从托管 Pod 的节点中的日志轮换文件.但是,此选项可能取决于 Kubernetes 实现,因为在触发 pod 驱逐时可能会删除日志文件.

Alternatively and given the logging architecture in Kubernetes, you might be able to fetch the logs directly from the log-rotate files in the node hosting the pods. However, this option might depend on the Kubernetes implementation as log files might be deleted when the pod eviction is triggered.

这篇关于如何查看已终止 Pod 的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆