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 →
- List pods by the Deployment's selector (
label_selector="app=api"). - For each pod, stream with
read_namespaced_pod_log(name, ns, container=c, follow=True, _preload_content=False)and iterateresp.stream()in a thread. - Prefix lines with pod name; push lines into a
queue.Queue, print from the main thread. - 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.
More on Kubernetes, Docker, SSH & fleet automation
You need a report of every pod in the cluster with no CPU or memory limits. How do you write it?BeginnerYou are asked to write a small operator-like script that adds a label to every new namespace. How do you approach it?AdvancedYou need to restart all Deployments in a namespace that reference a rotated Secret. How?AdvancedYour CI runners keep running out of disk because of Docker images. Write a cleanup plan in Python.IntermediateYou need to run `df -h` on 300 Linux hosts and list any above 85%. Python or Ansible?BeginnerA Python script SSHes to hosts with `AutoAddPolicy`. Security says that is unacceptable. What do you change?Intermediate