I have a discord bot that I have deployed on kubernetes. It is built into a docker image that I then deploy to k8s.
Dockerfile
:
FROM python:3.7
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED=0
CMD ["python", "-u", "main.py"]
deployment.yml
:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pythonapp
labels:
app: pythonapp
spec:
replicas: 1
selector:
matchLabels:
app: pythonapp
template:
metadata:
labels:
app: pythonapp
spec:
containers:
- name: pythonapp
image: registry.example.com/pythonapp:latest
imagePullPolicy: Always
env:
- name: PYTHONUNBUFFERED
value: "0"
When I deploy it, the program runs fine. But when I go to check the pod's logs, it says The selected container has not logged any messages yet.
.
How can I get anything that I print()
in python to be logged to the kubernetes pod?
PYTHONUNBUFFERED
must be set to 1
if you want to show log messages immediately without being buffered first.