Interview Prep/Python for DevOps/Kubernetes, Docker, SSH & fleet automation

You need to tail logs from all pods of a Deployment at once in a Python tool. How?

AdvancedScenarioKubernetes, Docker, SSH & fleet automation
Answer

Situation read → Multiple concurrent streams.

What I'd do →

  1. List pods by the Deployment's selector (label_selector="app=api").
  2. For each pod, stream with read_namespaced_pod_log(name, ns, container=c, follow=True, _preload_content=False) and iterate resp.stream() in a thread.
  3. Prefix lines with pod name; push lines into a queue.Queue, print from the main thread.
  4. Watch for new pods (rollouts) and start streams for them.

Why → One thread per stream is simple and the work is I/O bound.

Interview tip → Mention stern or kubectl logs -l app=api -f --prefix as existing tools before building one.

All Python for DevOps questions Roadmap: Python for automation

More on Kubernetes, Docker, SSH & fleet automation