Google Container Engine stdout Logs Not Showing Up

Deadly 提交于 2020-01-17 01:13:05

问题


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.

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")

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.


回答1:


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.

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.

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.




回答2:


If the logs aren't showing up when you run kubectl logs pod, then the problem is almost certainly that the logs from your application aren't going to stdout or stderr, so that's what you should focus on.

What happens if you docker run your application locally? Does docker logs then show the logs you expect? That should at least get you a faster iteration cycle to play around with different approaches to fixing it.



来源:https://stackoverflow.com/questions/37923927/google-container-engine-stdout-logs-not-showing-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!