tail multiple kubernetes pods

2 min read | by Jordi Prats

While debugging issues we might need to be able to see the output from multiple pods (or multiple) at the same time to be able to understand how they are interacting. Stern allows you to tail multiple pods on Kubernetes and even multiple containers within the pod

If we want to install without compiling it we just need to head to the stern's releases page to grab the binary that matches our architecture. For example, to install the amd64 version it would be:

$ sudo wget https://github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64 -O /usr/local/bin/stern
$ sudo chmod +x /usr/local/bin/stern

To test it we can create couple of pods (pod-a and pod-b) that will print either pod A or pod B:

apiVersion: v1
kind: Pod
metadata:
  name: pod-a
spec:
  containers:
    - name: web
      image: busybox
      command: [ 'sh', '-c', 'while true; do echo pod A; sleep 1; done' ]
---
apiVersion: v1
kind: Pod
metadata:
  name: pod-b
spec:
  containers:
    - name: web
      image: busybox
      command: [ 'sh', '-c', 'while true; do echo pod B; sleep 1; done' ]

Applying this yaml file we will be able to see that both pods have been created:

$ kubectl apply -f pods.yaml 
pod/pod-a created
pod/pod-b created

Now we just need to run stern using pod (since it is the common part of the name). It's output will look like:

$ stern pod
+ pod-b  web
+ pod-a  web
pod-a web pod A
pod-b web pod B
pod-a web pod A
pod-b web pod B
pod-a web pod A
(...)

On most of the terminals it will output each pod using a different color so it will be pretty easy to understand what's going on. On the stern's github page you can find more options to be able to filter pods, this is just the most simple use case


Posted on 03/06/2021

Categories