Streaming logs#

This example submits a long-running job that prints out logs using rich. Once the jobs is submitted, you can view the logs with kbatch pod logs <pod-id>, optionally streaming them with --stream.

We use this job configuration file:

# file: streaming-logs-config.yaml
name: streaming-logs
image: python:slim
command:
  - "sh"
  - "script.sh"
code: script.sh

The job runs this shell script:

#!/usr/bin/env bash
set -eux

python -m pip install rich
python -m rich.live

It’s submitted with

$ kbatch job submit -f config.yaml --output=name
job_id

We’ll use the job ID to get the pod ID

$ kbatch pod list --job-name=job_id --output=name
pod_id

With the pod ID, we can stream the logs

$ kbatch pod logs --job-name=job_id --stream