colorizes kubectl output

Overview

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/[email protected]

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

Issues
  • 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

    opened by jclynny 12
  • 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!!

    opened by bygui86 10
  • 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/[email protected]/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

    opened by rothgar 9
  • 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

    opened by laurentiuspurba 8
  • 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.

    opened by perbu 7
  • 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.

    opened by awinecki 7
  • Installation without depending on go get

    Installation without depending on go get

    Currently kubecolor can be installed via go get, but ideally it should not be depending on go command. We should:

    • enable kubecolor to be installed via package manager (homebrew etc)
    • distribute pre-build binary via GitHub release
    opened by hidetatz 5
  • kubectl process exit status lost with kubecolor

    kubectl process exit status lost with kubecolor

    kubecolor ignores the exit status of the kubectl process:

    $ /usr/bin/kubectl get pod foo; echo $?
    Error from server (NotFound): pods "foo" not found
    1
    $ kubecolor get pod foo; echo $?
    Error from server (NotFound): pods "foo" not found
    0
    

    (use-case: in a script (so the exit status is necessary), where a human still sees the outputs (so the color is much useful).)

    opened by thomas-riccardi 4
  • yaml color for `kubecolor apply -o yaml`

    yaml color for `kubecolor apply -o yaml`

    kubecolor 0.0.7: kubecolor apply -f foo.yaml -o yaml Actual result: all yaml output is green.

    Expected result: it would be great if the yaml output would be nicely colored like with kubecolor get pods -o yaml.

    opened by thomas-riccardi 4
  • panic: runtime error: index out of range [0]

    panic: runtime error: index out of range [0]

    kubecolor describe node xxx

    Capacity:
      attachable-volumes-gce-pd:panic: runtime error: index out of range [0] with length 0
    
    goroutine 6 [running]:
    github.com/dty1er/kubecolor/printer.(*DescribePrinter).Print(0xc000100f08, 0x535320, 0xc00000e030)
            /home/vlad/dev/oss/kubecolor/printer/describe.go:93 +0xc84
    github.com/dty1er/kubecolor/printer.Print(0x535320, 0xc00000e030, 0x535340, 0xc00000e018, 0xc000018980, 0x1)
            /home/vlad/dev/oss/kubecolor/printer/printer.go:81 +0x292
    github.com/dty1er/kubecolor/command.Run.func7()
            /home/vlad/dev/oss/kubecolor/command/runner.go:79 +0x97
    github.com/dty1er/kubecolor/command.runAsync.func1(0xc000076810, 0xc000016150)
            /home/vlad/dev/oss/kubecolor/command/runner.go:95 +0x27
    created by github.com/dty1er/kubecolor/command.runAsync
            /home/vlad/dev/oss/kubecolor/command/runner.go:94 +0x6e
    
    opened by slayer 4
  • Kubecolor breaks krew plugins using fzf (ctx + ns)

    Kubecolor breaks krew plugins using fzf (ctx + ns)

    Kubecolor breaks some krew plugins using fzf. For example, kubecolor ctx only lists the contexts with coloration instead of enabling the user to choose the context to switch to with fzf. Here's a screenshot : Capture d’écran du 2022-01-06 16-59-18 I'm using zsh, version 5.8 on Linux.

    opened by cterence 3
  • Color keys in the hierarchical output uniformly

    Color keys in the hierarchical output uniformly

    WHAT

    This PR is making the keys in hierarchical outputs (YAML, JSON, explain) to have the same color.

    WHY

    Having all keys of the same color improves readability of the output.

    opened by jtyr 0
  • install fail on homebrew on mac

    install fail on homebrew on mac

    brew install hidetatz/tap/kubecolor ==> 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 | 336.00 KiB/s, done. Resolving deltas: 100% (12/12), done. Error: Invalid formula: /usr/local/Homebrew/Library/Taps/hidetatz/homebrew-tap/Formula/kubecolor.rb kubecolor: wrong number of arguments (given 1, expected 0) Error: Cannot tap hidetatz/tap: invalid syntax in tap!

    opened by adrian-agot 2
  • Support recursive without argument

    Support recursive without argument

    WHAT

    This PR is adding the support for the --recursive command line argument that doesn't specify the boolean value (--recursive=true).

    WHY

    Some people don't specify the boolean value and because kubectl doesn't require it. With the current implementation, the explain output is completely broken if the boolean value is not specified.

    Related issue (if exists)

    N/A

    opened by jtyr 0
  • go install fails

    go install fails

    Instructions say:

    go install github.com/hidetatz/kubecolor/cmd/[email protected]
    

    But this results in:

    go install: github.com/hidetatz/kubecolor/cmd/[email protected]: github.com/hidetatz/[email protected]: parsing go.mod:
    	module declares its path as: github.com/dty1er/kubecolor
    	        but was required as: github.com/hidetatz/kubecolor
    
    opened by darkn3rd 3
  • go get fails

    go get fails

    Instructions say:

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

    But this results in

    go get: github.com/hidetatz/[email protected]: parsing go.mod:
    	module declares its path as: github.com/dty1er/kubecolor
    	        but was required as: github.com/hidetatz/kubecolor
    
    opened by darkn3rd 0
Releases(v0.0.20)
Owner
Hidetatsu Yaginuma
Hidetatsu loves infrastructures, database, concurrent programming, transactions, distributed systems
Hidetatsu Yaginuma
Kubectl golang - kubectl krew template repo

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

geodis 0 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

Steve Hoeksema 1 Jan 8, 2022
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

Eldad Rudich 2.4k Aug 12, 2022
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

sigstore 37 Jul 1, 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

Keisuke Umegaki 37 Jul 18, 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

Clusternet 11 May 27, 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

null 4 Nov 16, 2021
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

Segment 154 Aug 4, 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

Keisuke Umegaki 37 Jul 18, 2022
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

Ross Edman 3 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

Shin'ya Ueoka 11 Jul 25, 2022
Kubectl Locality Plugin - A plugin to get the locality of pods

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

John Howard 6 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

Christian Rebischke 16 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

寻寻觅觅的Gopher 7 Jun 20, 2022
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

Armin 0 Dec 20, 2021
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

Oracle 10 Aug 15, 2022
Dominik Robert 0 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

null 2 Apr 29, 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

Ludger Pottmeier 0 Jan 7, 2022