← 返回命令列表

Linux command

kubetail 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Tail pods matching a name pattern

kubetail [pod-name-prefix]

Tail pods by label selector

kubetail -l [app=myapp]

Tail in a specific namespace

kubetail [pattern] -n [namespace]

Tail a specific container

kubetail [pattern] -c [container]

Show only the last N minutes of logs

kubetail [pattern] -s [10m]

Show timestamps

kubetail [pattern] --timestamps

Tail with regex matching

kubetail "[^app1|.*demo.*]" --regex

Dry-run: list matching pods without tailing

kubetail [pattern] -d

说明

kubetail is a Bash script that aggregates and tails log output from multiple Kubernetes pods simultaneously. It matches pods by name prefix, regex, or label selector and streams their logs in a single terminal, using color-coded output to distinguish lines from different pods. The tool is useful when debugging distributed applications or microservices where related log entries are spread across several pod replicas. Under the hood, kubetail spawns multiple `kubectl logs --follow` processes and merges their output, optionally filtering by namespace, container, or duration. Defaults for most flags can be set via environment variables such as KUBETAIL_NAMESPACE, KUBETAIL_SINCE, KUBETAIL_TAIL, and KUBETAIL_COLORED_OUTPUT.

参数

-c, --container _NAME_
Container name (repeatable for multiple containers).
-t, --context _CONTEXT_
Kubernetes context to use.
-l, --selector _SELECTOR_
Label selector (e.g., app=myapp).
-n, --namespace _NAMESPACE_
Target namespace.
-e, --regex _MODE_
Match mode: regex or substring.
-s, --since _DURATION_
Show logs since relative duration (e.g., 10m, 1h).
-p, --previous _BOOL_
Retrieve logs from previous pod instances.
-f, --follow _BOOL_
Follow log stream (default true).
-d, --dry-run
Print matching pods/containers without tailing.
-k, --colored-output _MODE_
Coloring mode: pod, line (default), loglevel, or false.
-z, --skip-colors _LIST_
Comma-separated color indices to skip.
-P, --prefix _BOOL_
Toggle pod name prefix on each line.
-b, --line-buffered _BOOL_
Control line buffering.
-j, --jq _SELECTOR_
Apply jq selector to JSON log lines.
-r, --cluster _NAME_
Kubeconfig cluster name.
--tail _LINES_
Limit number of recent lines per pod.
--timestamps
Display timestamps on log lines.
-i, --show-color-index _BOOL_
Display color index with pod prefix.
-v, --version
Show version.
-h, --help
Display help information.

FAQ

What is the kubetail command used for?

kubetail is a Bash script that aggregates and tails log output from multiple Kubernetes pods simultaneously. It matches pods by name prefix, regex, or label selector and streams their logs in a single terminal, using color-coded output to distinguish lines from different pods. The tool is useful when debugging distributed applications or microservices where related log entries are spread across several pod replicas. Under the hood, kubetail spawns multiple `kubectl logs --follow` processes and merges their output, optionally filtering by namespace, container, or duration. Defaults for most flags can be set via environment variables such as KUBETAIL_NAMESPACE, KUBETAIL_SINCE, KUBETAIL_TAIL, and KUBETAIL_COLORED_OUTPUT.

How do I run a basic kubetail example?

Run `kubetail [pod-name-prefix]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --container _NAME_ do in kubetail?

Container name (repeatable for multiple containers).