Printing not being logged by Kubernetes

2/8/2019

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'?

-- irom
kubectl
kubernetes
logging
python
python-2.x

1 Answer

2/8/2019

Add the following to your Dockerfile:

ENV PYTHONUNBUFFERED=0
-- Soggiorno
Source: StackOverflow