LinuxCommandLibrary

kubetail

Tail logs from multiple Kubernetes pods

TLDR

Tail the logs of multiple pods (whose name starts with app_name) in one go

$ kubetail [app_name]
copy

Tail only a specific container from multiple pods
$ kubetail [app_name] [[-c|--container]] [container_name]
copy

Tail multiple containers from multiple pods
$ kubetail [app_name] [[-c|--container]] [container_name_1] [[-c|--container]] [container_name_2]
copy

Tail multiple applications at the same time separate them by comma
$ kubetail [app_name_1,app_name_2,...]
copy

SYNOPSIS

kubetail [options] [pod [pod ...]]

PARAMETERS

-c, --container <container>
    Output logs from the specified container in each pod

-f, --follow
    Follow logs in real-time (default: true)

-h, --help
    Display help message

-l, --selector <label_selector>
    Filter pods by label selector (e.g., app=nginx)

-n, --namespace <namespace>
    Target namespace (default: default)

-p, --pod-prefix <prefix>
    Show only pods starting with the given prefix

-q, --quiet
    Print only pod names, omitting log lines

-v, --version
    Show kubetail version

-V, --verbose
    Enable verbose logging

DESCRIPTION

Kubetail is a powerful Bash script designed for Kubernetes environments, enabling users to tail logs from multiple pods at once, similar to the Unix tail -f command but extended for containerized applications. It aggregates and interleaves log output from specified pods, namespaces, or label selectors, sorting them by pod name for easy readability.

Key features include following logs in real-time (-f), filtering by namespace (-n), label selectors (-l), container name (-c), or pod prefix (-p). Output can be quiet (-q, showing only pod names), verbose (-V), or colorized. It leverages kubectl under the hood to fetch logs, making it indispensable for debugging distributed systems.

Usage scenarios range from monitoring production clusters to troubleshooting deployments. Pods are discovered dynamically, and logs stream continuously until interrupted. It's lightweight, requiring no additional installations beyond kubectl and standard Unix tools like grep and awk. Widely used in DevOps workflows for its simplicity and effectiveness in handling high-volume log tailing across clusters.

CAVEATS

Requires kubectl configured with cluster access; performance degrades with hundreds of pods due to kubectl overhead; not suitable for non-Kubernetes environments; Bash-only, may need adjustments for other shells.

INSTALLATION

Download from GitHub:
curl -LO https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail && chmod +x kubetail
Or install via package managers like Homebrew: brew install kubetail

EXAMPLE

kubetail -n kube-system -l app=kube-dns tails logs from all kube-dns pods in kube-system namespace.
kubetail myapp-* tails all pods prefixed with myapp.

HISTORY

Developed by Johan Haleby in 2015 as an open-source GitHub project (johanhaleby/kubetail). Gained popularity in Kubernetes community for simplifying log aggregation pre-native kubectl logs enhancements. Actively maintained with updates for newer kubectl versions and features like color output.

SEE ALSO

kubectl(1), tail(1), multitail(1)

Copied to clipboard