python logs within kubernetes

by default, the logs won’t print out from the kubernetes pod. this is because Kubernetes would buffer the stdin, stdout, stdout.

the way to sort this out is make

PYTHONUNBUFFERED

If this is set to a non-empty string it is equivalent to specifying the -u option

in helm chart, something like this

kind: Service
apiVersion: v1
metadata:
  labels:
    app: example
  name: example
spec:
  ports:
  - port: 5000
    targetPort: 5000
  selector:
    app: example
---
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: example
  name: example
spec:
  replicas: 1
  strategy: {}
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: example
    spec:
      containers:
      - image: example
        imagePullPolicy: IfNotPresent
        name: example
        ports:
        - containerPort: 443
        resources: {}
        env:
          - name: PYTHONUNBUFFERED
            value: "0"
      restartPolicy: Always
status: {}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s