Cloud Native 10 min read

Master Real-Time Multi-Pod Logging in Kubernetes with Kubetail & Stern

This guide introduces two lightweight Kubernetes log‑tailing utilities, Kubetail and Stern, explaining their installation on various platforms, core command‑line options, and practical usage examples for aggregating and color‑coding logs from multiple pods and containers, offering a simpler alternative to heavyweight logging stacks.

Efficient Ops
Efficient Ops
Efficient Ops
Master Real-Time Multi-Pod Logging in Kubernetes with Kubetail & Stern

When a Kubernetes (K8s) service is deployed, monitoring logs is essential. While the typical Filebeat‑ElasticSearch‑Kibana stack works, it is heavyweight for a single internal service. Two lightweight tools, Kubetail and Stern, provide real‑time multi‑pod log tailing.

1. Kubetail

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 filtering.

1.1 Installation

Installation is straightforward and adapts to different platforms.

Homebrew

<code># install kubetail using brew
brew tap johanhaleby/kubetail && brew install kubetail
</code>

Linux

<code># download and to go
# https://github.com/johanhaleby/kubetail/releases
wget https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail
chmod +x kubetail
cp kubetail /usr/local/bin
</code>

zsh plugin

<code># oh-my-zsh
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/johanhaleby/kubetail.git kubetail

vim ~/.zshrc
plugins=( ... kubetail )
source ~/.zshrc
</code>

1.2 Usage

Easy to use; you can get started in two minutes.

Prepare pod list

<code># show all your pods -n test
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
app1-v1-m8acl      1/1     Running   0          6d
app1-v1-s20d0      1/1     Running   0          1d
app2-v31-9pbpn     1/1     Running   0          1d
app2-v31-q74wg     1/1     Running   0          1d
my-demo-v5-0fa8o   1/1     Running   0          3h
my-demo-v5-yhren   1/1     Running   0          2h
</code>

Tail logs from multiple pods

<code># tail logs from 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.*" --regex
</code>

Color options

<code># pod: only pod name colored
kubetail app2 -k pod
# line: whole line colored (default)
kubetail app2 -k line
# false: no color
kubetail app2 -k false
</code>

2. Stern

Multi pod and container log tailing for Kubernetes

Stern is a Go‑based, out‑of‑the‑box tool that aggregates logs from multiple pods and containers with colored output and filtering. It is no longer actively maintained, so use with caution.

2.1 Installation

Installation is straightforward and adapts to different platforms.

Homebrew

<code># install stern using brew
brew install stern
</code>

Linux

<code># download and to go
# https://github.com/wercker/stern/tags
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/bin
</code>

zsh plugin

<code># bash-completion
brew install bash-completion
source <(brew --prefix)/etc/bash-completion
source <(stern --completion=bash)

# zsh
source <(stern --completion=zsh)
</code>

2.2 Usage

Simple to use; you can get started in two minutes.

Prepare pod list

<code># show all your pods -n test
kubectl get pods -n test
... (output omitted for brevity)
</code>

Log tailing examples

<code># tail logs in current namespace
stern .

# tail logs from a specific container
stern app2 --container container1

# tail logs from a specific namespace
stern app2 --namespace namespace1

# exclude a container
stern --namespace namespace1 --exclude-container container1 .

# tail logs from last 15 minutes
stern app2 -t --since 15m

# filter by label
stern --all-namespaces -l run=nginx

# selector example
stern frontend --selector release=canary

# pipe to jq
stern backend -o json | jq .

# raw output
stern backend -o raw

# custom template
stern --template '{{.Message}} ({{.Namespace}}/{{.PodName}}/{{.ContainerName}})' backend
</code>
clicloud nativeKuberneteslog aggregationkubetailstern
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.