kubectl icon indicating copy to clipboard operation
kubectl copied to clipboard

Add ANSI colors to kubectl describe and other outputs

Open izelnakri opened this issue 7 years ago • 81 comments

FEATURE REQUEST:

Currently kubectl outputs are pretty boring without a color:

kubetest_ -bash _181x31

Adding color to them will make them easier to read. Each key could be colored based on its indentation level. Each key/value pair in labels,annotations,taints etc could be colored differently as well.

izelnakri avatar Aug 24 '18 18:08 izelnakri

Maybe a good idea

cnfatal avatar Aug 28 '18 06:08 cnfatal

/kind feature /sig cli /area kubectl /priority P2

seans3 avatar Sep 26 '18 00:09 seans3

Specifically I would expect colorization on get -o yaml and get -o json. At least for the latter, you can work around this by

kubectl get -o json $type $name | jq .

jglick avatar Dec 20 '18 15:12 jglick

@jglick as a work around you can use something like https://www.npmjs.com/package/cli-highlight then run:

kubectl get -o json $type $name | highlight

That's what I do currently :)

bossjones avatar Jan 04 '19 21:01 bossjones

You could also use vim -R to preview the contents with some (limited) color highlighting

kubectl get $type $name | vim -R -c 'set syntax=yaml' -

since that is a lot to type, you may want to wrap that in a bash function

function vaml() {
  vim -R -c 'set syntax=yaml' -;
}

then you can simply pipe to the function

kubectl get $type $name | vaml

spuder avatar Jan 30 '19 17:01 spuder

This would be really helpful to see the difference between "Pending" and "Running" on get pods. Right now they're hard to distinguish:

Running
Running
Running
Pending
Running
Running

geekofalltrades avatar Feb 15 '19 23:02 geekofalltrades

It would be great to highlight pods in "kubectl get pods" where # of ready containers < total # of containers

mdz avatar May 10 '19 20:05 mdz

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Aug 08 '19 21:08 fejta-bot

/remove-lifecycle stale

izelnakri avatar Aug 11 '19 22:08 izelnakri

This would be so helpful. Anyone working on a PR for this?

austinorth avatar Aug 29 '19 13:08 austinorth

Having colorized output for kubectl get nodes would be fantastically helpful.

meltingrobot avatar Oct 10 '19 13:10 meltingrobot

@geekofalltrades I use this: GREP_COLOR='01;32' egrep --color=always 'Running|$' | GREP_COLOR='01;33' egrep --color=always 'ContainerCreating|$' | GREP_COLOR='01;33' egrep --color=always 'Terminating|$' | GREP_COLOR='01;31' egrep --color=always 'Error|$' | GREP_COLOR='01;31' egrep --color=always 'CrashLoopBackOff|$' | GREP_COLOR='01;31' egrep --color=always 'ImagePullBackOff|$' | GREP_COLOR='01;33' egrep --color=always 'Pending|$'

save it as a file lets say k8s_color

and then:

kubectl get pods | source k8s_color

I know its not elegant solution but it gets the job done

image

lukjaw avatar Oct 23 '19 10:10 lukjaw

Any news on this?

TomaszKlosinski avatar Nov 15 '19 09:11 TomaszKlosinski

As a work around you can use bat then run:

$ kubectl get pods -o yaml | bat -l yaml

apemost avatar Dec 17 '19 09:12 apemost

Another weird work around

kubectl get pods | ccze -A -o nolookups

It would be great if someone writes a "kubernetes plugin" for CCZE :)

a0s avatar Feb 10 '20 21:02 a0s

Or in alternative you could try yh for YAML output

$ kubectl get pods -o yaml | yh

Comparison with or without yh

andreazorzetto avatar Apr 26 '20 12:04 andreazorzetto

This issue is opened for almost 2 years. Is it on the roadmap?

TomaszKlosinski avatar Apr 27 '20 07:04 TomaszKlosinski

I am currently using zsh instead of bash and antigen to manage zsh "plugins", one of them is "antigen bundle c-castillo/ccze" which resides in github.com/c-castillo/ccze

for kubectl get X color I have added the jq plugin to zsh so I use kubectl "-o json" and then press ALT-J and I Can see the colors for the json output of kubectl command, and to stuff with it using jq. maybe yq can be added to the mix @andreazorzetto

I think it would be nice to start from there since handy shortcuts can be made and kubectl can be added to a list of commands ccze can process, thought I haven't checked how it manages the rules for the coloring.

here's my current .zshrc :

source ~/antigen.zsh
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle reegnz/jq-zsh-plugin
antigen bundle c-castillo/ccze
export PATH=/snap/bin:$PATH
set -g mouse on
powerline-daemon -q 
#tmux new
source /usr/share/powerline/bindings/zsh/powerline.zsh
POWERLINE_CONFIG_COMMAND=powerline-config
#powerline-config tmux setup
# Set up the prompt
source /usr/share/powerlevel9k/powerlevel9k.zsh-theme
autoload -Uz promptinit
promptinit
prompt adam1
setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi

bindkey "\033[1~" beginning-of-line
bindkey "\033[4~" end-of-line

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=10000
HISTFILE=~/.zsh_history

# Use modern completion system
autoload -Uz compinit
compinit

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
antigen apply

gattytto avatar May 03 '20 21:05 gattytto

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale. Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale

fejta-bot avatar Aug 01 '20 22:08 fejta-bot

/remove-lifecycle stale

izelnakri avatar Aug 03 '20 05:08 izelnakri

Just FYI I've made a CLI tool to do this. https://github.com/dty1er/kubecolor

hidetatz avatar Oct 10 '20 13:10 hidetatz

Cheers @dty1er and thanks for sharing.

Would be good to have you join us for a future sig-cli meeting to talk potential for getting your work upstream.

https://github.com/kubernetes/community/tree/master/sig-cli#meetings

eddiezane avatar Oct 14 '20 19:10 eddiezane

Hi @eddiezane . Wow nice! I am willing to join the meeting and want to talk about kubecolor with you guys. When will you have a next one?

hidetatz avatar Oct 17 '20 16:10 hidetatz

@dty1er next meeting will be November 4th. You'll get a calendar invite if you join the mailing list.

eddiezane avatar Oct 21 '20 18:10 eddiezane

Will join the next one!

hidetatz avatar Oct 23 '20 14:10 hidetatz

This was discussed today.

Take away is we'll need to create a KEP and then determine the challenge of implementation and maintainer burden. Is this supported server side or client side?

Recording if anyone is interested https://youtu.be/NtmbMqWCbOI?t=1322

eddiezane avatar Nov 04 '20 23:11 eddiezane

Starting working on writing KEP, will share the one once it's ready here

hidetatz avatar Nov 06 '20 05:11 hidetatz

Any KEP in progress ? :-)

miton18 avatar Jan 14 '21 17:01 miton18

/cc dougsland

dougsland avatar Jan 16 '21 00:01 dougsland

Sorry for the delay of my work. It is not forgotten but I'm just getting busy for my work :(

hidetatz avatar Jan 18 '21 03:01 hidetatz