랭킹으로 돌아가기

johanhaleby/kubetail

Shell

Bash script to tail Kubernetes logs from multiple pods at the same time

kubernetesbashpodtail
스타 성장
스타
3.5k
포크
291
주간 성장
이슈
28
1k2k3k
2015년 12월2019년 6월2023년 1월2026년 7월
README

Kubetail

Bash script that enables you to aggregate (tail/follow) logs from multiple pods into one stream. This is the same as running "kubectl logs -f " but for multiple pods.

Installation

Just download the kubetail file (or any of the releases) and you're good to go.

Homebrew

You can also install kubetail using brew:

$ brew install johanhaleby/kubetail/kubetail

It's also possible to install kubetail abbreviated to kt by using the --with-short-names suffix:

$ brew install johanhaleby/kubetail/kubetail --with-short-names

Note that you may need to run compinit for zsh to pick-up the changes in competition after having upgraded from the non abbreviated installation.

Use brew install --HEAD johanhaleby/kubetail/kubetail to install the latest (unreleased) version.

ASDF

You can install kubetail using the asdf version manager.

asdf plugin-add kubetail https://github.com/janpieper/asdf-kubetail.git
asdf install kubetail <version>

To find out the available versions to install, you can run the following command:

asdf list-all kubetail

ZSH plugin

If you're using a ZSH plugin manager, you can install kubetail as a plugin.

Antigen

If you're using Antigen:

  1. Add antigen bundle johanhaleby/kubetail to your .zshrc where you've listed your other plugins.
  2. Close and reopen your Terminal/iTerm window to refresh context and use the plugin. Alternatively, you can run antigen bundle johanhaleby/kubetail in a running shell to have antigen load the new plugin.

oh-my-zsh

If you're using oh-my-zsh:

  1. In the command line, change to oh-my-zsh's custom plugin directory :

    cd ~/.oh-my-zsh/custom/plugins/

  2. Clone the repository into a new kubetail directory:

    git clone https://github.com/johanhaleby/kubetail.git kubetail

  3. Edit your ~/.zshrc and add kubetail – same as clone directory – to the list of plugins to enable:

    plugins=( ... kubetail )

  4. Then, restart your terminal application to refresh context and use the plugin. Alternatively, you can source your current shell configuration:

    source ~/.zshrc

zgen

If you're using zgen:

  1. Add zgen load johanhaleby/kubetail to your .zshrc along with your other zgen load commands.
  2. zgen reset && zgen save

Completion

The easiest option is to install kubetail from homebrew to dynamically display the pods names on $ kubetail <tab>. Alternatively install any of the completion scripts (bash/zsh/fish) manually. For example:

  • On Ubuntu, download the kubetail.bash script and execute it in your ~/.bash_completion file source $HOME/kubetail/completion/kubetail.bash.
  • On Mac with zsh copy the kubetail.zsh script to /usr/local/share/zsh/site-functions/_kubetail.
  • On Mac with fish copy the kubetail.fish script to ~/.config/fish/completions/.

Don't forget to restart your terminal afterwards.

Usage

First find the names of all your pods:

$ kubectl get pods

This will return a list looking something like this:

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

To tail the logs of the two "app2" pods in one go simply do:

$ kubetail app2

To tail only a specific container from multiple pods specify the container like this:

$ kubetail app2 -c container1

You can repeat -c to tail multiple specific containers:

$ kubetail app2 -c container1 -c container2

To tail multiple applications at the same time separate them by comma:

$ kubetail app1,app2

For advanced matching you can use regular expressions:

$ kubetail "^app1|.*my-demo.*" --regex

To tail logs within a specific namespace, make sure to append the namespace flag after you have provided values for containers and applications:

$ kubetail app2 -c container1 -n namespace1

Supply -h for help and additional options:

$ kubetail -h

Colors

By using the -k argument you can specify how kubetail makes use of colors (only applicable when tailing multiple pods).

Value Description
pod Only the pod name is colorized but the logged text is using the terminal default color
line The entire line is colorized (default)
false Don't colorize the output at all

Example:

$ kubetail app2 -k false

If you find that some colors are difficult to see then they can be skipped by supplying the color index either to the -z flag or by setting the KUBETAIL_SKIP_COLORS environment variable (either choice could be comma separated). To find the color index you'd like to skip more easily, set the -i flag to true (-i true) or set the KUBETAIL_SHOW_COLOR_INDEX environment variable to true (KUBETAIL_SHOW_COLOR_INDEX=true). This will print the color index as a prefix to the pod name (e.g. [3:my-pod-12341] some log where 3 is the index of the color). This is also helpful if you suffer from color blindness since the index will always be printed with the default terminal color.

Filtering / Highlighting etc

kubetail itself doesn't have filtering or highlighting capabilities built-in. If you're on MacOSX I recommend using iTerm2 which allows for continuous highlighting of search terms, good scrolling capabilities and multitab arrangements. Another useful feature of iTerm2 is the "timeline" (cmd + shift + e) which lets you display a timeline in your own local timezone next to the logs (that are typically in UTC).

If you're not using iTerm2 or think that kubetail is lacking in features there's a fork of kubetail made by Alan Stebbens that allows for richer configuration and uses multitail and bash-lib. Alan has been kind enough to provide a pull request but my current thinking is that I'd like kubetail to stay simple and small and not use any dependencies.

Environment

kubetail can take default option values from environment variables matching the option name.

KUBETAIL_PREVIOUS
KUBETAIL_SINCE
KUBETAIL_NAMESPACE
KUBETAIL_FOLLOW
KUBETAIL_PREFIX
KUBETAIL_LINE_BUFFERED
KUBETAIL_COLORED_OUTPUT
KUBETAIL_TIMESTAMPS
KUBETAIL_JQ_SELECTOR
KUBETAIL_SKIP_COLORS
KUBETAIL_TAIL
KUBETAIL_SHOW_COLOR_INDEX

More

Pull requests are very welcome!

See also: http://code.haleby.se/2015/11/13/tail-logs-from-multiple-pods-simultaneously-in-kubernetes/

Buy Me A Coffee

관련 저장소
kubernetes/kubernetes

Production-Grade Container Scheduling and Management

GoGo ModulesApache License 2.0kubernetesgo
kubernetes.io
123.9k43.7k
bregman-arie/devops-exercises

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

PythonPyPIOtherdevopsaws
83.3k19.8k
netdata/netdata

The fastest path to AI-powered full stack observability, even for lean teams.

GoGo ModulesGNU General Public License v3.0monitoringdocker
netdata.cloud
79.8k6.5k
traefik/traefik

The Cloud Native Application Proxy

GoGo ModulesMIT Licensemicroservicedocker
traefik.io
64.1k6.1k
minio/minio

MinIO is a high-performance, S3 compatible object store, open sourced under GNU AGPLv3 license.

GoGo ModulesGNU Affero General Public License v3.0gostorage
61.4k7.7k
etcd-io/etcd

Distributed reliable key-value store for the most critical data of a distributed system

GoGo ModulesApache License 2.0etcdraft
etcd.io
52k10.4k
GitHubDaily/GitHubDaily

坚持分享 GitHub 上高质量、有趣实用的开源技术教程、开发者工具、编程网站、技术资讯。A list cool, interesting projects of GitHub.

githubopen-source
githubdaily.com
47.1k4.7k
LeCoupa/awesome-cheatsheets

👩‍💻👨‍💻 Awesome cheatsheets for popular programming languages, frameworks and development tools. They include everything you should know in one single file.

JavaScriptnpmMIT Licensecheatsheetsjavascript
lecoupa.github.io/awesome-cheatsheets/
46.2k6.7k
Kong/kong

🦍 The API and AI Gateway

LuaApache License 2.0api-gatewaymicroservices
konghq.com/install/
43.8k5.2k
istio/istio

Connect, secure, control, and observe services.

GoGo ModulesApache License 2.0microservicesservice-mesh
istio.io
38.3k8.3k
ToolJet/ToolJet

ToolJet is the open-source foundation of ToolJet AI - the enterprise app generation platform for building internal tools, dashboard, business applications, workflows and AI agents 🚀

JavaScriptnpmGNU Affero General Public License v3.0javascriptinternal-tools
tooljet.com
38.2k5.2k
portainer/portainer

Making Docker and Kubernetes management easy.

TypeScriptnpmzlib Licensedockerdocker-swarm
portainer.io
38k2.9k