Kubernetes未记录打印

时间:2019-02-08 17:28:47

标签: python logging kubernetes python-2.x kubectl

我在Kubernetes(AKS)的容器中运行了简单的python 2.7程序,该程序将调试信息打印到标准输出中

response = requests.post(uri,data=body, headers=headers)
if (response.status_code >= 200 and response.status_code <= 299):
    print 'Accepted ' + log_type + ' on ' + rfc1123date
else:
    print "Response code: {}".format(response.status_code)

我在kubectl logs container_name中看不到它,输出为空(但我知道这很好,因为发布成功)。我尝试在Dockerfile中将"-u"添加到CMD ["-u","syslog2la.py"],但这没有帮助。如何在“ kubectl日志”中获取python打印?

1 个答案:

答案 0 :(得分:2)

将以下内容添加到您的Dockerfile中:

ENV PYTHONUNBUFFERED=0