Convert Figma logo to code with AI

johanhaleby logokubetail

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

3,322
290
3,322
35

Top Related Projects

1,970

kubernetes log viewer

This repository is no longer maintained, please checkout https://github.com/JamesTGrant/kubectl-debug.

17,537

Faster way to switch between clusters and namespaces in kubectl

26,434

🐶 Kubernetes CLI To Manage Your Clusters In Style!

Quick Overview

Kubetail is a bash script that allows you to aggregate (tail/follow) logs from multiple Kubernetes pods into one stream. It's particularly useful for debugging and monitoring applications running across multiple pods in a Kubernetes cluster.

Pros

  • Simplifies log viewing for multi-pod applications
  • Supports various filtering options (by label, container, namespace, etc.)
  • Colorizes output for better readability
  • Lightweight and easy to install

Cons

  • Limited to bash environments
  • May become less performant with a large number of pods
  • Doesn't provide advanced log analysis features
  • Requires manual updates for new versions

Getting Started

  1. Install kubetail:
brew tap johanhaleby/kubetail && brew install kubetail

Or download the script directly:

curl -o /usr/local/bin/kubetail https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail
chmod +x /usr/local/bin/kubetail
  1. Basic usage:
kubetail my-app-pod
  1. Tail logs from multiple pods:
kubetail "pod1|pod2|pod3"
  1. Tail logs from pods with a specific label:
kubetail -l app=my-app
  1. Tail logs from a specific container in pods:
kubetail my-app-pod -c my-container
  1. Tail logs from pods in a specific namespace:
kubetail my-app-pod -n my-namespace

These examples demonstrate the basic usage of kubetail. For more advanced options and configurations, refer to the project's README on GitHub.

Competitor Comparisons

1,970

kubernetes log viewer

Pros of kail

  • Written in Go, offering better performance and cross-platform compatibility
  • Supports container filtering, allowing more granular log selection
  • Provides color-coded output for easier log reading

Cons of kail

  • Requires installation of a binary, unlike kubetail which is a bash script
  • Less widespread adoption compared to kubetail
  • May have a steeper learning curve for users familiar with kubetail

Code comparison

kubetail:

#!/bin/bash
kubectl logs -f $@ | sed -e 's/^/[/' -e 's/$/]/'

kail:

func (c *Client) Tail(ctx context.Context, opts TailOptions) (<-chan string, <-chan error) {
    // Implementation details
}

Summary

Both kubetail and kail are tools for tailing Kubernetes logs. kubetail is a simple bash script that leverages kubectl, making it easy to use and modify. kail, on the other hand, is a more feature-rich Go application that offers advanced filtering and better performance. The choice between the two depends on specific requirements, such as ease of use versus advanced features and performance.

This repository is no longer maintained, please checkout https://github.com/JamesTGrant/kubectl-debug.

Pros of kubectl-debug

  • Provides advanced debugging capabilities, including running debug containers alongside target pods
  • Supports multiple debugging modes (e.g., ephemeral container, node-shell)
  • Offers a rich set of pre-built debugging tools and images

Cons of kubectl-debug

  • More complex setup and usage compared to kubetail's straightforward log tailing
  • Requires additional permissions and RBAC configuration for full functionality
  • May have a steeper learning curve for users new to Kubernetes debugging

Code Comparison

kubetail:

kubetail my-pod-label

kubectl-debug:

kubectl debug -it my-pod --image=busybox:latest --target=my-pod

Key Differences

  • Purpose: kubetail focuses on log aggregation, while kubectl-debug provides comprehensive debugging tools
  • Functionality: kubetail is simpler and more specialized, kubectl-debug offers broader debugging capabilities
  • Use cases: kubetail is ideal for quick log viewing, kubectl-debug is better for in-depth troubleshooting

Conclusion

Both tools serve different purposes in the Kubernetes ecosystem. kubetail excels at simplifying log viewing across multiple pods, while kubectl-debug offers a more robust set of debugging features for complex issues. The choice between them depends on the specific debugging needs and the user's familiarity with Kubernetes concepts.

17,537

Faster way to switch between clusters and namespaces in kubectl

Pros of kubectx

  • Offers both context and namespace switching functionality
  • Includes fuzzy search for easier selection
  • Provides shell completion for improved usability

Cons of kubectx

  • Focuses on context/namespace management, not log tailing
  • Requires additional setup for some features (e.g., fzf for fuzzy search)

Code Comparison

kubectx:

kubectx my-cluster
kubens my-namespace

kubetail:

kubetail my-pod
kubetail -l app=my-app

Summary

kubectx and kubetail are distinct tools serving different purposes in the Kubernetes ecosystem. kubectx simplifies context and namespace switching, while kubetail focuses on log tailing across multiple pods. kubectx offers broader cluster management functionality, including fuzzy search and shell completion. However, it doesn't provide log tailing capabilities like kubetail.

kubetail excels in its specific use case of aggregating logs from multiple pods, making it invaluable for debugging and monitoring. It supports various filtering options and can tail logs from multiple pods simultaneously.

The choice between these tools depends on the specific task at hand: use kubectx for efficient context and namespace management, and kubetail for streamlined log viewing across pods.

26,434

🐶 Kubernetes CLI To Manage Your Clusters In Style!

Pros of k9s

  • Comprehensive CLI-based UI for managing Kubernetes clusters
  • Real-time resource monitoring and management
  • Supports multiple views and customizable hotkeys

Cons of k9s

  • Steeper learning curve due to more complex interface
  • Requires more system resources than simpler tools

Code Comparison

k9s (configuration example):

k9s:
  refreshRate: 2
  maxConnRetry: 5
  enableMouse: false
  headless: false
  logoless: false
  crumbsless: false
  readOnly: false
  noIcons: false

kubetail (usage example):

kubetail my-pod-name
kubetail my-pod-name -n my-namespace
kubetail -l app=my-app

Summary

k9s is a feature-rich, interactive CLI tool for managing Kubernetes clusters, offering real-time monitoring and extensive functionality. It provides a more comprehensive solution but may require more resources and time to master.

kubetail, on the other hand, is a simpler, focused tool specifically designed for tailing Kubernetes logs. It's easier to use for quick log viewing but lacks the broader management capabilities of k9s.

Choose k9s for a full-featured Kubernetes management experience, or kubetail for straightforward log tailing with minimal overhead.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

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 tap johanhaleby/kubetail && brew install kubetail

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

$ brew tap johanhaleby/kubetail && brew install 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 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 seperate 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).

ValueDescription
podOnly the pod name is colorized but the logged text is using the terminal default color
lineThe entire line is colorized (default)
falseDon'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 seperated). 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