Quickly Tail Logs from Multiple Kubernetes Pods with Kubetail and Stern
This guide introduces two lightweight Kubernetes log‑tailing tools—Kubetail and Stern—explaining their installation on various platforms, core command‑line options, and practical usage examples for aggregating and filtering pod logs in real time.
1. Kubetail Tool
Bash script to tail Kubernetes logs from multiple pods at the same time
Kubetail is a simple shell script that aggregates logs from multiple pods, supports colored output and conditional filtering.
1.1 Installation
Installation is straightforward and adapts to different platforms.
Homebrew
# install kubetail using brew
$ brew tap johanhaleby/kubetail && brew install kubetailLinux
# download and install
$ wget https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail
$ chmod +x kubetail
$ cp kubetail /usr/local/binZsh plugin
# oh-my-zsh
$ cd ~/.oh-my-zsh/custom/plugins/
$ git clone https://github.com/johanhaleby/kubetail.git kubetail
$ vim ~/.zshrc
plugins=( ... kubetail )
$ source ~/.zshrc1.2 Usage
Very easy to use; you can get started in about 2 minutes.
Prepare pod list
# show all your pods
$ kubectl get pods -n test
NAME READY STATUS RESTARTS AGE
app1-v1-aba8y 1/1 Running 0 1d
app1-v1-gc4st 1/1 Running 0 1d
... (other pods)Tail logs
# tail logs of two "app2" pods
$ kubetail app2
$ kubetail app1,app2
# specify container name
$ kubetail app2 -c container1
$ kubetail app2 -c container1 -c container2
$ kubetail app2 -c container1 -n namespace1
# use regex
$ kubetail "^app1|.*my-demo.*" --regexColor options
# pod: only pod names colored
# line: whole line colored (default)
# false: no color
$ kubetail app2 -k pod
$ kubetail app2 -k line
$ kubetail app2 -k falseCommon flags
-n: specify namespace -c: specify container name in multi‑container pod -k: enable colored output -b: use line‑buffered mode (default false) -l: label filter to ignore pod names -t: show logs since a relative time (e.g., 5s, 2m, 3h, default 10s)
2. Stern Tool
Multi pod and container log tailing for Kubernetes
Stern is a Go‑based, ready‑to‑use tool that aggregates logs from multiple pods with colored output and conditional filtering. It is no longer actively maintained, so use with caution.
2.1 Installation
Installation is straightforward and adapts to different platforms.
Homebrew
# install stern using brew
$ brew install sternLinux
# download and install
$ wget https://github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64
$ chmod +x stern_linux_amd64
$ mv stern_linux_amd64 /usr/local/binZsh plugin
# bash completion
$ brew install bash-completion
$ source <(brew --prefix)/etc/bash-completion
$ source <(stern --completion=bash)
# zsh completion
$ source <(stern --completion=zsh)2.2 Usage
Very easy to use; you can get started in about 2 minutes.
Prepare pod list
# show all your pods
$ kubectl get pods -n test
... (output omitted)Tail logs
# tail all logs in the current namespace
$ stern .
# tail logs of a specific container
$ stern app2 --container container1
# tail logs in a specific namespace
$ stern app2 --namespace namespace1
# exclude a container
$ stern --namespace namespace1 --exclude-container container1 .
# tail logs from the last 15 minutes
$ stern app2 -t --since 15m
# filter by label across all namespaces
$ stern --all-namespaces -l run=nginx
# filter by selector (e.g., canary release)
$ stern frontend --selector release=canary
# pipe logs to jq for JSON processing
$ stern backend -o json | jq .
# output raw log messages only
$ stern backend -o raw
# custom template output
$ stern --template '{{.Message}} ({{.Namespace}}/{{.PodName}}/{{.ContainerName}})' backend
# template with colored pod and container names
$ stern --template '{{.Message}} ({{.Namespace}}/{{color .PodColor .PodName}}/{{color .ContainerColor .ContainerName}})' backendCommon flags
--container: container name regex (default .*) --exclude-container: container name regex to exclude --container-state: filter by container state (default running) --timestamps: print timestamps --since: show logs newer than a relative duration --context: Kubernetes context to use --exclude: exclude log lines by regex --namespace: namespace to use --kubeconfig: path to kubeconfig file (default ~/.kube/config) --all-namespaces: tail across all namespaces --selector: label selector query --tail: number of lines from the end (default -1) --color: force color output (auto, always, never) --output: predefined output format (default, raw, json)
3. Reference Links
johanhaleby/kubetail
wercker/stern
Two highly useful Kubernetes real‑time log viewing tools
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
