Home > front end >  Cannot see python print statements when I execute kubectl logs <pod>
Cannot see python print statements when I execute kubectl logs <pod>

Time:10-21

I'm working on a simple python 3 application that would be using print statements. It is crutial for me to see the logs when i execute kubectl log command. However, the logs are never present. It looks like the application may not be running in the pod. When i'm executing kubectl --it exexc and go in to pod I land up in working directory, then when i manually execute python myApp.py it is printing the logs.

My Dockerfile looks like this:

FROM python:3.8-slim-buster

ENV PYTHONUNBUFFERED=0

WORKDIR /code

COPY . .

CMD [ "python", "/.main.py" ]

For a simple example I can use a piece of code which just prints:

from time import sleep

while True:
    print("Im printing ...")
    sleep(10)

My pod definition look like this:

apiVersion: v1
kind: Pod
metadata:
  name: logbox
  namespace: default
spec:
  containers:
    - name: logbox
      image: <8888888888888888>logbox:0.0.1
      imagePullPolicy: "IfNotPresent"
      stdin: true
      args:
        - sh
        - -c
        - sleep infinity

CodePudding user response:

It might be that the args commands in the pod definition are overriding the Dockerfile CMD command, I'd give it a try without the definition args or by matching them (so the args calls the python ./main.py

  • Related