Repo of the Day
johanhaleby/kubetail
Published: Nov 24, 2023
Open repository ↗Bash script to tail Kubernetes logs from multiple pods at the same time
Summary
Kubetail is a Bash script that aggregates logs from multiple Kubernetes pods into a single stream, behaving like kubectl logs -f but applied to many pods at once. It supports pod-name matching, container selection, namespace targeting, regex filtering, and color coding to distinguish log sources. The tool ships as a single script and integrates with Homebrew, ASDF, and several ZSH plugin managers.
What it is useful for
Kubetail is useful for engineers who need to observe or debug applications running across several Kubernetes pods without juggling multiple terminal sessions. Typical situations include:
- Investigating load-balanced or replicated services where requests are spread across pods, since a single
kubetail app2call follows every matching replica in one view. - Watching logs during rolling deployments to compare behavior of new and old replicas side by side.
- Correlating logs from multiple containers within the same pod using repeated
-cflags, for examplekubetail app2 -c container1 -c container2. - Tailing several applications at once by passing comma-separated names, such as
kubetail app1,app2. - Targeting a specific namespace with
-n namespace1, which the README notes must be supplied after the pod and container arguments.
How engineers can use it
The README documents several install paths. The simplest is downloading the script directly. Homebrew users can run:
brew tap johanhaleby/kubetail
brew install johanhaleby/kubetail/kubetail
The --with-short-names suffix additionally installs a kt alias. The project also publishes ASDF and ZSH plugin instructions (Antigen, oh-my-zsh, zgen) and standalone bash, zsh, and fish completion scripts.
A typical workflow starts by listing pods, then invoking kubetail with a substring of the pod name. Examples from the README include:
kubetail app2to follow all pods whose names contain "app2".kubetail "^app1|.*my-demo.*" --regexfor regex-based matching.kubetail app2 -c container1 -n namespace1to scope to one container and namespace.
Color output is controlled with -k, accepting pod, line (the default), or false. The -i true flag prefixes each pod name with a numeric color index, which the README highlights as useful for color-blind users. Defaults such as namespace, follow mode, timestamps, or a jq selector can be set through environment variables like KUBETAIL_NAMESPACE, KUBETAIL_FOLLOW, and KUBETAIL_JQ_SELECTOR.
Documented limitations: kubetail intentionally omits built-in filtering and highlighting. The README suggests iTerm2's search and timeline features for that workflow, and notes a community fork that wraps multitail for richer configuration, though the maintainer chose not to merge it to keep dependencies minimal. Tab completion also requires either the Homebrew install or a manual copy of the completion scripts, and zsh users may need to run compinit after upgrading from the non-abbreviated install.