未显示Kubernetes Pod的登录 [英] Logs in Kubernetes Pod not showing up
问题描述
我已经设置了Kubernetes并在pod中运行grpc服务.我成功地在服务上命中了一个端点,该端点上有一个print()语句,但是在日志文件中看不到任何日志.我在Kubernetes中运行(cron)作业之前就已经看到了这一点,并且日志仅在作业完成后才出现(而不是在作业运行时).有没有办法让kubernetes立即写入日志文件?我可以设置任何设置(集群级别还是仅用于Pod)?感谢您的任何提前帮助!
I have Kubernetes set up and running a grpc service in a pod. I am successfully hitting an endpoint on the service, which has a print() statement in it, but I see no logs in the log file. I have seen this before when I was running a (cron) job in Kubernetes and the logs only appeared after the job was done (as opposed to when the job was running). Is there a way to make kubernetes write to the log file right away? Any setting that I can put (either cluster-level or just for the pod)? Thanks for any help in advance!
推荐答案
找到了根本原因.具体来说,请在> Python应用无法打印的情况下找到它在docker中独立运行时的所有内容.解决方案是设置以下环境变量:PYTHONUNBUFFERED = 0.并非未显示打印语句,而是正在缓冲打印语句.进行上述操作即可解决问题.
Found the root cause. Specifically, found it at Python app does not print anything when running detached in docker . The solution is to set the following environmental variable: PYTHONUNBUFFERED=0 . It was not that the print statement was not being displayed, it was that the print statement was being buffered. Doing the above will solve the issue.
这篇关于未显示Kubernetes Pod的登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!