add the following statements immediately after the echo "Okteto into service" entry in devcontainer/rscripts/setup_dev_terminal.sh
echo "Make okteto-pod logs available to \`kubectl logs <okteto-pod-name>\` command"
echo " Start the service through this command: python manage.py runserver 0.0.0.0:8000 2>&1 | tee /proc/1/fd/1"
echo " notes: combine stderr(2) and stdout(1) from django and broadcast them(tee) to okteto-pod's terminal(seen by user) and PID-1(used by kubectl)"
These forward the logs generated in an okteto pod to PID-1 that's used by kubectl logs command to query logs for a specific pod.
Explanation:
Kubectl logs only takes logs from process PID 1
- In non-okteto’d state, the
python manage.py runserver ... command runs on PID1, hence fetching the logs of a non-okteto’d pod works.
- Whereas post okteto’ing, PID1 (which can be verified by running the command
cat /proc/1/cmdline after okteto’ing into the pod) is the okteto binary file (/var/okteto/bin/okteto-supervisor--remote--verbose=false)
- tee duplicates stdout into your terminal and /proc/1/fd/1 (PID 1’s stdout)
- 2>&1 combines whatever Django has printed to stdout and stderr respectively.
add the following statements immediately after the
echo "Okteto into service"entry indevcontainer/rscripts/setup_dev_terminal.shThese forward the logs generated in an okteto pod to PID-1 that's used by
kubectl logscommand to query logs for a specific pod.Explanation:
Kubectllogs only takes logs from process PID 1python manage.py runserver ...command runs on PID1, hence fetching the logs of a non-okteto’d pod works.cat /proc/1/cmdlineafter okteto’ing into the pod) is the okteto binary file (/var/okteto/bin/okteto-supervisor--remote--verbose=false)