pythonloggingkubernetespython-2.xkubectl

Printing not being logged by Kubernetes


I have simple python 2.7 program running in container off Kubernetes (AKS) which is printing debug information to standard output

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)

I don't see it with kubectl logs container_name, output is empty (but I know it is fine because of successful post). I tried to add "-u" to CMD ["-u","syslog2la.py"] in Dockerfile, but it didn't help. How to get the python print in 'kubectl logs'?


Solution

  • Add the following to your Dockerfile:

    ENV PYTHONUNBUFFERED=0