How to get logs of two pods without opening two terminals and using kubectl tail command?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
You do not need two terminals to watch two Kubernetes pods at once. In many cases, plain kubectl logs can stream multiple pods in one command if you target them through a label selector or a workload resource. The cleanest solution is usually to select the pods by label instead of hard-coding their names.
Use a label selector with kubectl logs
If the two pods share a label, this is the simplest built-in approach:
This gives you one combined stream.
The useful pieces are:
- '
-fto keep following the logs' - '
-l app=my-apito select multiple matching pods' - '
--all-containers=trueif the pods have sidecars or multiple containers' - '
--prefixto show which pod and container produced each line'
Without --prefix, a combined stream becomes much harder to read.
Target the workload instead of pod names
If the pods belong to the same Deployment, you can often use the workload name rather than individual pod names.
This is useful because pod names are ephemeral. A rollout or restart changes the pod names, but the Deployment name stays stable.
Improve readability with time filters
Mixed logs get noisy quickly, so narrow the output when debugging.
This limits the stream to recent lines and adds timestamps, which makes correlating events between pods much easier.
When the pods are unrelated
If the two pods do not share a useful label and you really need exactly those two names in one terminal, kubectl logs becomes awkward. That is the point where a tool such as Stern is often a better fit.
Stern is popular because it handles multiple pods naturally and keeps following logs as pods restart.
Still, before adding another tool, ask whether the labels should be improved. In a well-labeled cluster, related pods are usually easy to select together.
There is no standard kubectl tail command
A common source of confusion is the phrase kubectl tail. Standard kubectl has kubectl logs. If you see tail in a workflow, it is usually:
- a shell alias
- a plugin
- a wrapper command
That matters because the built-in logging behavior is documented under kubectl logs, not under a separate standard tail subcommand.
Common Pitfalls
The biggest pitfall is selecting too many pods with a broad label. Always verify the selector with kubectl get pods -l ... before assuming the combined stream only covers the two pods you care about.
Another issue is forgetting --prefix. Once multiple streams are merged, source labels are essential.
It is also easy to hard-code pod names from a Deployment and then wonder why the command breaks after a restart or rollout.
Finally, if the pods are truly unrelated, do not force a fragile one-liner when a dedicated multi-pod log tool or better labeling would be clearer.
Summary
- Use
kubectl logs -f -l ... --prefixwhen the pods share labels. - Use a workload target such as a Deployment when pod names are ephemeral.
- Add
--timestampsand--sinceto keep mixed logs readable. - Use Stern or a similar tool only when you need multiple arbitrary pod names in one stream.
- Good labels are usually the cleanest long-term solution.
Related reading
- How to get number of pods running in prometheus
- How to get pods under the service with client-go the client library of kubernetes?
- How to get real-time resource usage of a pod in k8s?
- How to get running pod status via Rest API
- How to get pipenv running in docker?
- How to get specific namespace for log fluentd
- How to get self pod with kubernetes client-go
- How to get the current namespace of current context using kubectl
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.