colorizes kubectl output

kubecolor

test Go Report Card codecov

Colorize your kubectl output

  • get pods

image

  • describe pods

image

  • something wrong

image

  • You can change color theme for light-backgrounded environment

image

What's this?

kubecolor colorizes your kubectl command output and does nothing else. kubecolor internally calls kubectl command and try to colorizes the output so you can use kubecolor as a complete alternative of kubectl. It means you can write this in your .bash_profile:

alias kubectl="kubecolor"

If you use your .bash_profile on more than one computer (e.g. synced via git) that might not all have kubecolor installed, you can avoid breaking kubectl like so:

command -v kubecolor >/dev/null 2>&1 && alias kubectl="kubecolor"

kubecolor is developed to colorize the output of only READ commands (get, describe...). So if the given subcommand was for WRITE operations (apply, edit...), it doesn't give great decorations on it.

For now, not all subcommands are supported and will be done in the future. What is supported can be found below. Even if what you want to do is not supported by kubecolor now, kubecolor still can just show kubectl output without any decorations, so you don't need to switch kubecolor and kubectl but you always can use kubecolor.

Additionally, if kubectl resulted an error, kubecolor just shows the error message in red or yellow.

Installation

Download binary via GitHub release

Go to Release page then download the binary which fits your environment.

Mac and Linux users via Homebrew

brew install dty1er/tap/kubecolor

Manually via go command

Note: if you install kubecolor via go command, --kubecolor-version command might not work

go install github.com/dty1er/kubecolor/cmd/kubecolor@latest

If you are not using module mode (or if just above doesn't work), try below:

go get -u github.com/dty1er/kubecolor/cmd/kubecolor

Usage

kubecolor understands every subcommands and options which are available for kubectl. What you have to do is just using kubecolor instead of kubectl like:

kubecolor --context=your_context get pods -o json

If you want to make the colorized kubectl default on your shell, just add this line into your shell configuration file:

alias kubectl="kubecolor"

Flags

  • --kubecolor-version

Prints the version of kubecolor (not kubectl one).

  • --plain

When you don't want to colorize output, you can specify --plain. Kubecolor understands this option and outputs the result without colorizing. Of course, given --plain will never be passed to kubectl. This option will help you when you want to save the output onto a file and edit them by editors.

  • --light-background

When your terminal's background color is something light (e.g white), default color preset might look too bright and not readable. If so, specify --light-background as a command line argument. kubecolor will use a color preset for light-backgrounded environment.

  • --force-colors

By default, kubecolor never output the result in colors when the tty is not a terminal. If you want to force kubecolor to show the result in colors for non-terminal tty, you can specify this flag. For example, when you want to pass kubecolor result to grep (kubecolor get pods | grep pod_name), this option is useful.

Autocompletion

kubectl provides autocompletion feature. If you are already using it, you might have to configure it for kubecolor. Please also refer to kubectl official doc for kubectl autorcomplete.

Bash

For Bash, configuring autocompletion requires adding following line in your shell config file.

# autocomplete for kubecolor
complete -o default -F __start_kubectl kubecolor

If you are using an alias like k="kubecolor", then just change above like:

complete -o default -F __start_kubectl k

Zsh

For zsh make sure these lines are present in your zsh config file:

# get zsh complete kubectl
source <(kubectl completion zsh)
alias kubectl=kubecolor
# make completion work with kubecolor
compdef kubecolor=kubectl

fish

Fish completion is officially unsupported by kubectl, so it is unsupported by kubecolor as well.

However, there are 2 ways we can make them work. Please keep in mind these are a kind of "hack" and not officially supported.

  1. Use evanlucas/fish-kubectl-completions with kubecolor:

  2. Use awinecki/fish-kubecolor-completions

    The first way will override kubectl command. If you wish to preserve both kubectl and kubecolor with completions, you need to copy evanlucas/fish-kubectl-completions for the kubecolor command.

    For this purpose, you can use awinecki/fish-kubecolor-completions.

Specify what command to execute as kubectl

Sometimes, you may want to specify which command to use as kubectl internally in kubecolor. For example, when you want to use a versioned-kubectl kubectl.1.19, you can do that by an environment variable:

KUBECTL_COMMAND="kubectl.1.19" kubecolor get po

When you don't set KUBECTL_COMMAND, then kubectl is used by default.

Supported kubectl version

Because kubecolor internally calls kubectl command, if you are using unsupported kubectl version, it's also not supported by kubecolor. Kubernetes version support policy can be found in official doc.

Krew

Krew is unsupported for now.

Contributions

Always welcome. Just opening an issue should be also greatful.

LICENSE

MIT

Owner
Hidetatsu Yaginuma
Hidetatsu loves infrastructures, database, concurrent programming, transactions, distributed systems
Hidetatsu Yaginuma
Comments
  • autocompletion bug

    autocompletion bug

    this could very well have to do with my setup, but I'm getting something weird from the first word of autocomplete.

    if i tab from kubecolor, i get kubecolor $'\033'\[33m kubecolor de doesn't complete

    but kubecolor get, does work and gives me all the right options

  • Enhanced readability with colors

    Enhanced readability with colors

    color the status in yellow or red, depending on the severity

    no color is used for normal status, like Running. Green is not used in order to avoid the confusion with red color for color blind users.

    yellow is used for warnings and transional status, like Pending - very useful to differentiate Pending and Running.

    red is used for failed, error, ... status

    because strings contain the most information, and white is the most readable color, strings are changed to white color.

    table output is changed to two alternating colors, to enhance the readability of the columns without using too many colors

    key indent color alternates between yellow and cyan to enhance the indent readability and differentiate the key from the content

    while it would be great to enhance the readability of the help page, coloring everything in yellow doesn't seem to help for that purpose. As for strings, white is more readable and seems more suited for this complex content

    Related issue (if exists)

  • Error when running `kubectl describe namespace <namespace>`

    Error when running `kubectl describe namespace `

    I am on Mac OSX v. 10.15.7 (Catalina) and Kubecolor 0.0.7 installed from brew, and I'm using zsh in iTerm2. I get the following errors when trying to describe namespace resources in K8s:

    Resource Quotas Name:panic: runtime error: index out of range [0] with length 0

    goroutine 18 [running]: github.com/dty1er/kubecolor/printer.(*DescribePrinter).Print(0xc00005e010, 0x113d2e0, 0xc0000a2028, 0x113d300, 0xc0000a2008) /home/runner/work/kubecolor/kubecolor/printer/kubectl_describe.go:85 +0xe75 github.com/dty1er/kubecolor/printer.(*KubectlOutputColoredPrinter).Print(0xc000082340, 0x113d2e0, 0xc0000a2028, 0x113d300, 0xc0000a2008) /home/runner/work/kubecolor/kubecolor/printer/kubectl_output_colored_printer.go:101 +0x15e github.com/dty1er/kubecolor/command.Run.func1(0xc00009a0a0, 0x113d820, 0xc0000a2028, 0xc0000a8040) /home/runner/work/kubecolor/kubecolor/command/runner.go:85 +0x9b created by github.com/dty1er/kubecolor/command.Run /home/runner/work/kubecolor/kubecolor/command/runner.go:84 +0x34c image

  • Brew installation method does not work

    Brew installation method does not work

    ==> Tapping hidetatz/tap
    Cloning into '/usr/local/Homebrew/Library/Taps/hidetatz/homebrew-tap'...
    remote: Enumerating objects: 59, done.
    remote: Counting objects: 100% (59/59), done.
    remote: Compressing objects: 100% (55/55), done.
    remote: Total 59 (delta 12), reused 8 (delta 0), pack-reused 0
    Receiving objects: 100% (59/59), 7.89 KiB | 2.63 MiB/s, done.
    Resolving deltas: 100% (12/12), done.
    Error: Invalid formula: /usr/local/Homebrew/Library/Taps/hidetatz/homebrew-tap/Formula/kubecolor.rb
    kubecolor: Calling bottle :unneeded is disabled! There is no replacement.
    Please report this issue to the hidetatz/tap tap (not Homebrew/brew or Homebrew/core):
      /usr/local/Homebrew/Library/Taps/hidetatz/homebrew-tap/Formula/kubecolor.rb:9
    
    Error: Cannot tap hidetatz/tap: invalid syntax in tap!
    Failed to install [hidetatz/tap/kubecolor]
    Some packages were not installed
    
    ==> Some tasks were not executed successfully
    

    Unsure where the error is, seems in brew formula

  • Kubecolor autocompletion does not work and break canonical k alias

    Kubecolor autocompletion does not work and break canonical k alias

    I tried to enable the autocompletion for kubecolor following instructions on the official README:

    Basically, configuring autocompletion for kubecolor requires adding following line in your shell config file.

    # autocomplete for kubecolor
    complete -o default -F __start_kubectl kubecolor
    

    If you are using an alias like k="kubecolor", then just change above like:

    complete -o default -F __start_kubectl k
    

    but it does not work, no autocompletion for kubecolor and even worse no autocompletion anymore for k alias!

    Here some info:

    • OS: macos catalina v10.15.7
    • kubectl: official v1.20.2
    • k alias set and autocompletion properly working (without enabling kubecolor autocompletion)

    Here the output of kubectl version command:

    $ kubectl version
    
    Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-14T05:14:17Z", GoVersion:"go1.15.6", Compiler:"gc", Platform:"darwin/amd64"}
    

    Any help is really appreciated!!

  • Add Goreleaser support for releases and homebrew

    Add Goreleaser support for releases and homebrew

    WHAT

    This adds a config for goreleaser to manually create releases via goreleaser release and also automatically via github actions when a new tag is pushed. I have an example in my fork and tap repo. brew install rothgar/tap/kubecolor works.

    You'll need to create a github repo called dty1er/homebrew-tap/ and you'll need to create a GITHUB_TOKEN with access to push into that repo. You can read more about it here https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow

    You can create the token at https://github.com/settings/tokens It should only need repo access. If you want to use goreleaser to publish .rpm and .deb packages or docker containers you can also add package access.

    You should make sure the token is set up in the repo settings as GITHUB_TOKEN so goreleaser can use it automatically.

    Let me know if you run into problems or have questions. :+1:

    WHY

    So releases are automatic and brew install works

    Related issue

    Fixes #27

  • Autocomplete does not work.

    Autocomplete does not work.

    Hello @dty1er

    I have kubecolor updated after running go get -u github.com/dty1er/kubecolor/cmd/kubecolor. I also have the following in my.zshrc

    # kubecolor
    alias kubectl=kubecolor
    complete -o default -F __start_kubectl kubectl
    

    So, when I typed kubectl command, my autocomplete did not work. Then, I removed the above kubecolor config in my .zshrc, and ran source ~/.zshrc to get the latest changes on my src file.

    I re-tried kubectl again, and the autocomplete still did not work.

    After I removed that kubecolor config, I checked the following:

    ▶ which kubectl
    kubectl: aliased to kubecolor
    ▶ which kubecolor
    /Users/lpurba/go/bin/kubecolor
    

    Why the autocomplete did not work? Also, after removing kubecolor config and sourceing the src file, why my kubectl was still an alias of kubecolor?

    Having autocomplete is very helpful. I appreciate your help

    Thank you, Laurentius

  • colored object age

    colored object age

    WHAT

    Fresh object according to age is colored as green. Fresh threshold level is configurable value by setting environment variable, with default set as 5 minutes.

    WHY

    It's much easier to figure out which objects are recently created ie. created by k8s hpa.

    Related issue (if exists)

  • fix(completions): Do not colorize output for bash completions

    fix(completions): Do not colorize output for bash completions

    WHAT

    The bash completion for kubectl use internal subcommands. Internal subcommands start with __. These should never be colorized.

    WHY

    Because it fixes an existing problem with the bash completions.

    Related issue (if exists)

    Relates to: #78 Fixes at least my problem: https://github.com/hidetatz/kubecolor/issues/78#issuecomment-986071841

  • colorizing kubectl apply

    colorizing kubectl apply

    Hi!

    This looks like a nice and useful project. I like colors. I switched from curl to httpie because colors.

    Would you be interested in me attempting to colorize kubectl apply? Currently it is all green. I'd like it to be mostly white, with separate colors for actions that are "unchanged", "created", "configured", etc.

    I've not looked at the code so I don't know if it fits. Let me know. Any other tips for an implementation would be welcome.

    Cheers Per.

  • feat: add fish shell completions to README

    feat: add fish shell completions to README

    Hello; such a great project! I'm just learning k8s, and I like my CLI UI to be clean and readable.

    As I've been using fish for a while now, I was sad to discover I can't use kubecolor with proper completions with fish. Completions are necessary to me for learning, so I tried to make it work.

    As I'm no expert when it comes to hacking fish, I just took @evanlucas (thx ! 🙏 ) completions, and replaced all kubectl with kubecolor. It's ugly, but it works.

    @evanlucas, perhaps you could guide me how to do it in a cleaner way. I know little about go, and seems you're using it to generate these completions. Worst case, I could just set up a github action that periodically fetches your kubectl completions and builds kubecolor ones from that.

  • Better color schema

    Better color schema

    While I believe kubecolor colorizes the kubectl output nicely, I don't think current implementation is best. The better color schema might be found in the future.

    Now, there are a lot of color schema change requests:

    https://github.com/hidetatz/kubecolor/issues/110 https://github.com/hidetatz/kubecolor/issues/102 https://github.com/hidetatz/kubecolor/issues/91 https://github.com/hidetatz/kubecolor/issues/89 https://github.com/hidetatz/kubecolor/issues/88 https://github.com/hidetatz/kubecolor/issues/77 https://github.com/hidetatz/kubecolor/issues/76

    It will be possible to implement all the things, but I'm concerned the kubecolor will be not very simple and not easy to use. In the first place, this kind of thing is completely personal preference.

    In my opinion, we have to options:

    • Keep it simple. No color customization ability in kubecolor. If you don't like it's color schema, you can fork and change it.
    • Make kubecolor configurable. Imagine vim's syntax highlighting configuration. The configuration file will look like this:
    # ~/.config/kubecolor/schema.yml
    dark: true
    color:
      get:
        base_color: blue
        warn_color: red
        highlight_crush_loop_backoff: true
    ...
    

    Two things on the second option:

    • Will we really want to write this file?
    • What's the format of the file?

    I don't want to make kubecolor too complicated, I want to keep it simple as much as possible. However, the really useful feature should be builtin without configuration file. I want to gather the opinion.

  • switching between light and dark background

    switching between light and dark background

    Hello,

    First of all - love the tool, discovered it recently and really happy with the functionality.

    Second of all, I need suggestions for my setup. So I'm using the latest iTerm2 (v3.5) that supports switching color preset (including background) based on the system automatically enabled/disabled dark mode, e.g., if the system is set to light mode during the day, I have the light solarized background, if it's dark mode - I have dark solarized.

    As per this suggestion, I'm using scripts and aliases to switch manually between kubecolor and kubecolor --light-background, but wonder if there is more automatic way to switch?

  • AUR package is in need of new maintainer

    AUR package is in need of new maintainer

    kubecolor has been packaged in the AUR for some time, but was recently abandoned by the previous maintainer. A new maintainer is welcome to adopt the package. You should have knowledge of AUR conventions, PKGBUILD, and makepkg.

    Good luck :)

  • kubecolor inconsistent output

    kubecolor inconsistent output

    i have inconsistent output (sometime dup, sometime disappear, order change) when i use kubecolor versus direct kubectl

    • Screenshot of "kubectl" output image

    • Screenshot of "kubecolor" output

    i launch it 4 times

    image

    • What's the issue and what you expect

    i expect to have the same output as with kubectl with color of course

    • Shell info (bash/zsh/fish etc, its version)

    zsh 5.8 kubectl v1.21.0 kubecolor 0.0.20

Kubectl golang - kubectl krew template repo

kubectl krew template repo There's a lot of scaffolding needed to set up a good

Jan 11, 2022
A simple tool to extract Fronius solar data logger output and output Influx line protocol

telegraf-exec-fronius This is a simple tool to extract Fronius solar data logger output and output Influx line protocol; it is designed to be used wit

Jan 8, 2022
Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark
Kubectl plugin to ease sniffing on kubernetes pods using tcpdump and wireshark

ksniff A kubectl plugin that utilize tcpdump and Wireshark to start a remote capture on any pod in your Kubernetes cluster. You get the full power of

Jan 4, 2023
kubectl plugin for signing Kubernetes manifest YAML files with sigstore
kubectl plugin for signing Kubernetes manifest YAML files with sigstore

k8s-manifest-sigstore kubectl plugin for signing Kubernetes manifest YAML files with sigstore ⚠️ Still under developement, not ready for production us

Nov 28, 2022
A kubectl plugin for finding decoded secret data with productive search flags.

kubectl-secret-data What is it? This is a kubectl plugin for finding decoded secret data. Since kubectl only outputs base64-encoded secrets, it makes

Dec 2, 2022
A 'kubectl' plugin for interacting with Clusternet.

kubectl-clusternet A kubectl plugin for interacting with Clusternet. Installation Install With Krew kubectl-clusternet can be installed using Krew, pl

Aug 14, 2022
kubetnl tunnels TCP connections from within a Kubernetes cluster to a cluster-external endpoint, e.g. to your local machine. (the perfect complement to kubectl port-forward)

kubetnl kubetnl (kube tunnel) is a command line utility to tunnel TCP connections from within a Kubernetes to a cluster-external endpoint, e.g. to you

Dec 16, 2022
Kubectl plugin to run curl commands against kubernetes pods

kubectl-curl Kubectl plugin to run curl commands against kubernetes pods Motivation Sending http requests to kubernetes pods is unnecessarily complica

Dec 22, 2022
A kubectl plugin for finding decoded secret data with productive search flags.

kubectl-secret-data What is it? This is a kubectl plugin for finding decoded secret data. Since kubectl outputs base64-encoded secrets basically, it m

Dec 2, 2022
A kubectl plugin for getting endoflife information about your cluster.
A kubectl plugin for getting endoflife information about your cluster.

kubectl-endoflife A kubectl plugin that checks your clusters for component compatibility and Kubernetes version end of life. This plugin is meant to a

Jul 21, 2022
A kubectl plugin to evict pods

kubectl-evict A kubectl plugin to evict pods. This plugin is good to remove a pod from your cluster or to test your PodDistruptionBudget. ?? Installat

Dec 7, 2022
Kubectl Locality Plugin - A plugin to get the locality of pods

Kubectl Locality Plugin - A plugin to get the locality of pods

Nov 18, 2021
kubectl plugin for generating nginx-ingress compatible basic-auth secrets on kubernetes clusters

kubectl-htpasswd kubectl plugin for easily generating hashed basic auth secrets. Supported hash algorithms bcrypt Examples Create the secret on the cl

Jul 17, 2022
🦥 kubectl plugin to easy to view pod

kubectl-lazy Install curl -sSL https://mirror.ghproxy.com/https://raw.githubusercontent.com/togettoyou/kubectl-lazy/main/install.sh | bash Or you can

Oct 13, 2022
This is kubectl-plugins repository
This is kubectl-plugins repository

golang CLI Template golang project template for building CLI Setup Setup by Command git clone https://github.com/mpppk/cli-template your_awesome_tool

Dec 20, 2021
The Coherence command line interface (CLI) is a lightweight tool, in the tradition of tools such as kubectl
The Coherence command line interface (CLI) is a lightweight tool, in the tradition of tools such as kubectl

Coherence Command Line Interface (CLI) Contents Overview Why use the Coherence C

Dec 15, 2022
Jan 4, 2022
A replacement for "kubectl exec" that works over WebSocket connections.

kubectl-execws A replacement for "kubectl exec" that works over WebSocket connections. Kubernetes API server has support for exec over WebSockets, but

Sep 23, 2022
Simple tool to generate dockerconfigjon. This use snippets from kubectl.

gen-dockercfg Simple tool to generate dockerconfigjon. This use snippets from kubectl. Usage: gen-dockercfg -email string Registry email -pas

Jan 7, 2022