LinuxCommandLibrary

stern

Multi-pod Kubernetes log tailing

TLDR

Tail pod logs

$ stern [pod-query]
copy
Tail with namespace
$ stern -n [namespace] [pod-query]
copy
All namespaces
$ stern --all-namespaces [pod-query]
copy
Specific container
$ stern -c [container] [pod-query]
copy
Since duration
$ stern --since [10m] [pod-query]
copy
Show timestamps
$ stern -t [pod-query]
copy
Regex pod matching
$ stern --selector [app=nginx]
copy
Output format
$ stern -o json [pod-query]
copy

SYNOPSIS

stern [-n namespace] [-c container] [--since duration] [options] pod-query

DESCRIPTION

stern allows you to tail log output from multiple Kubernetes pods and containers simultaneously. It accepts a pod name query (which can be a regular expression) and streams log lines from all matching pods, automatically including new pods as they appear and removing terminated ones.
Each pod and container is assigned a distinct color in the output, making it easy to visually distinguish which log lines come from which source. Stern supports filtering by namespace, container name, and label selectors, and can output logs in various formats including JSON for structured processing.
The tool is particularly useful for debugging microservices where related functionality spans multiple pods or deployments. Unlike `kubectl logs`, which can only follow a single pod at a time, stern aggregates logs across any number of matching pods and gracefully handles pod restarts and scaling events in real time.

PARAMETERS

-n, --namespace NS

Kubernetes namespace.
--all-namespaces, -A
All namespaces.
-c, --container NAME
Container name.
--since DURATION
Logs since duration.
-t, --timestamps
Show timestamps.
-o, --output FORMAT
Output format.
-s, --selector SELECTOR
Label selector.
--tail N
Lines per container.

CAVEATS

Requires kubectl access. Many pods may overwhelm. Network latency affects streaming.

HISTORY

stern was created by Wercker (now Oracle) for Kubernetes log tailing. It simplifies viewing logs from multiple pods simultaneously.

SEE ALSO

kubectl(1), kubetail(1), k9s(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community