Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logs in Kubernetes Pod not showing up

I have Kubernetes set up and running a grpc service in a pod. I am successfully hitting an endpoint on the service, which has a print() statement in it, but I see no logs in the log file. I have seen this before when I was running a (cron) job in Kubernetes and the logs only appeared after the job was done (as opposed to when the job was running). Is there a way to make kubernetes write to the log file right away? Any setting that I can put (either cluster-level or just for the pod)? Thanks for any help in advance!

like image 786
HeronAlgoSearch Avatar asked May 14 '17 23:05

HeronAlgoSearch


2 Answers

Found the root cause. Specifically, found it at Python app does not print anything when running detached in docker . The solution is to set the following environmental variable: PYTHONUNBUFFERED=0 . It was not that the print statement was not being displayed, it was that the print statement was being buffered. Doing the above will solve the issue.

like image 76
HeronAlgoSearch Avatar answered Oct 07 '22 04:10

HeronAlgoSearch


Here is an example of K8S deployment yaml so you can copy paste the solution from the aforementioned answer:

root@k8s:~/python_docker$ cat deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hpa
spec:
  selector:
    matchLabels:
      app: hpa
  template:
    metadata:
      labels:
        app: hpa
    spec:
      containers:
      - name: hpa
        image: my-hpa/py
        env:
        - name: PYTHONUNBUFFERED
          value: "0"
        resources:
          requests:
            cpu: 100m
            memory: 200Mi
like image 20
Andrej Avatar answered Oct 07 '22 03:10

Andrej