Skip to content

Add instructions to forward okteto-pod logs so that kubectl logs command can access them. #2

@akshayrw25

Description

@akshayrw25

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions