问题描述
我的标准输出日志未显示在Google Logs Viewer中,或使用kubectl logs <pod>
时.群集已启用云日志记录,并且流利的容器在每个节点上运行.
My stdout logs are not showing up in Google Logs Viewer, or when using kubectl logs <pod>
. The cluster has Cloud Logging enabled and fluentd containers are running on each node.
Python示例代码:
Example Python code:
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
logger.addHandler(handler)
logger.info("test log")
来自其文档的反容器"示例确实适用我的集群,所以流利的容器正在拾取stdout并将其发送到Logs Viewer.
The "counter-pod" example from their docs does work on my cluster, so the fluentd containers are picking up stdout and sending it to Logs Viewer.
对我应该尝试的事情有什么建议吗?预先感谢.
Any suggestions for things I should try? Thanks in advance.
推荐答案
日志肯定会输出到stdout,在运行kubectl logs <pod_name>
时它们不会显示.它们也不会显示在Google Logs Viewer中.
The logs are definitely going to stdout, they just aren't showing up when running kubectl logs <pod_name>
. Nor are they showing up in Google Logs Viewer.
这是因为发送到stdout的日志仅在它们来自Docker容器入口点的进程中时才会被捕获.在shell中或通过cron作业完成的事情不会显示.
This is because logs sent to stdout will only be captured if they're coming from the process that's the entry point of the Docker container. Things that are done in the shell or via a cron job don't show up.
在我的情况下,我有一个cron作业正在调用脚本.通过将脚本作为容器的入口点运行,日志可以正常显示.
In my case I had a cron job that was invoking a script. By running the script as the container's entry point, the logs showed up fine.
这篇关于Google Container Engine标准输出日志未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!