Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 423
irom Avatar asked Feb 08 '19 17:02

irom


People also ask

How do I resolve Imagepullbackoff in Kubernetes?

To resolve it, double check the pod specification and ensure that the repository and image are specified correctly. If this still doesn't work, there may be a network issue preventing access to the container registry. Look in the describe pod text file to obtain the hostname of the Kubernetes node.

What is CrashLoopBackOff in Kubernetes?

What is Kubernetes CrashLoopBackOff? CrashLoopBackOff is a common error that you may have encountered when running your first containers on Kubernetes. This error indicates that a pod failed to start, Kubernetes tried to restart it, and it continued to fail repeatedly.

How do you show logs in Kubernetes?

You can see the logs of a particular container by running the command kubectl logs <container name> .


1 Answers

Add the following to your Dockerfile:

ENV PYTHONUNBUFFERED=0
like image 167
Soggiorno Avatar answered Oct 13 '22 01:10

Soggiorno