Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ANSI colors to kubectl describe and other outputs #524

Open
izelnakri opened this issue Aug 24, 2018 · 74 comments
Open

Add ANSI colors to kubectl describe and other outputs #524

izelnakri opened this issue Aug 24, 2018 · 74 comments
Assignees
Labels
area/kubectl kind/feature Categorizes issue or PR as related to a new feature. priority/P2 sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@izelnakri
Copy link

izelnakri commented Aug 24, 2018

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.

@cnfatal
Copy link

cnfatal commented Aug 28, 2018

Maybe a good idea

@seans3
Copy link
Contributor

seans3 commented Sep 26, 2018

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

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. sig/cli Categorizes an issue or PR as relevant to SIG CLI. area/kubectl priority/P2 labels Sep 26, 2018
@jglick
Copy link

jglick commented Dec 20, 2018

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 .

@bossjones
Copy link

@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 :)

@spuder
Copy link

spuder commented Jan 30, 2019

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

@geekofalltrades
Copy link

geekofalltrades commented Feb 15, 2019

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

@mdz
Copy link

mdz commented May 10, 2019

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

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 8, 2019
@izelnakri
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 11, 2019
@austinorth
Copy link

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

@meltingrobot
Copy link

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

@lukjaw
Copy link

lukjaw commented Oct 23, 2019

@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

@TomaszKlosinski
Copy link

Any news on this?

@apemost
Copy link

apemost commented Dec 17, 2019

As a work around you can use bat then run:

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

@a0s
Copy link

a0s commented Feb 10, 2020

Another weird work around

kubectl get pods | ccze -A -o nolookups

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

@andreazorzetto
Copy link

andreazorzetto commented Apr 26, 2020

Or in alternative you could try yh for YAML output

$ kubectl get pods -o yaml | yh

Comparison with or without yh

@TomaszKlosinski
Copy link

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

@gattytto
Copy link

gattytto commented May 3, 2020

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

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 1, 2020
@izelnakri
Copy link
Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 3, 2020
@hidetatz
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Apr 24, 2023
@h3ct0rjs
Copy link

h3ct0rjs commented Jun 5, 2023

/remove-lifecycle rotten

@jainpratik163
Copy link

when this feature is coming?

@TomaszKlosinski
Copy link

Any updates?

@felipecrs
Copy link

Now that kubecolor is archived, I believe this is more important than ever. :)

@h3ct0rjs
Copy link

I agree completely with @felipecrs that we need to add support to this, this also helps people who have special eyes 👀 , this will increase the accessibility to kubectl.

@gurpalw
Copy link

gurpalw commented Sep 21, 2023

workaround so far:
https://github.com/itaysk/kubectl-neat

alias in my .zshrc file:

alias kneat="kubectl neat | yq"

Then i pipe my get commands to kneat.

kubectl get nodes -l gitlab=true -o yaml | kneat

@WladyX
Copy link

WladyX commented Sep 22, 2023

workaround so far: https://github.com/itaysk/kubectl-neat

alias in my .zshrc file:

alias kneat="kubectl neat | yq"

Then i pipe my get commands to kneat.

kubectl get nodes -l gitlab=true -o yaml | kneat

Gold, thanks for sharing.

@h3ct0rjs
Copy link

h3ct0rjs commented Oct 3, 2023

This feature should be built-in. but in any case, is a good hack, thanks @WladyX

Best Regards,
H

@husanu
Copy link

husanu commented Nov 10, 2023

/assign

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 8, 2024
@ovk
Copy link

ovk commented Feb 8, 2024

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 8, 2024
@abhimanyu003
Copy link

abhimanyu003 commented Apr 18, 2024

Sharing trick based on @spuder comment earlier but using bat: A cat(1) clone with wings.
https://github.com/sharkdp/bat

kubectl get $type $name -oyaml | cat -l yaml --paging=never

Alias

function vml() {
  cat -l yaml --paging=never
}
kubectl get $type $name -oyaml | vml

Output

image

PS: this is using gruvbox-dark theme from bat.
Also please note that here bat is aliased to cat alias cat='bat --paging=never' from the bat docs.

@felipecrs
Copy link

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

For reference, here's the new maintained one: https://github.com/kubecolor/kubecolor

@briantopping
Copy link

Maybe the answer we are looking for here is the ability to locally remap kubectl commands. Consider:

  • The kubectl command tree is a standard, don't break that
  • Local user customizations shouldn't need a different command tree (i.e. kubecolor) to do the same things
  • Introducing aspects such as colorization may break environments that have script dependencies on CLI output

The ability to generically override commands as a part of the login context would cover these bases. A service account with no overrides would get raw output, users who had customizations would get their preferred output format without having to use a different command set.

A final tweak on this would be to allow krew to update the override config. So if someone installed kubecolor, existing commands would be automatically remapped upon installation without magic.

@felipecrs
Copy link

Honestly, I think that's overengineering. kubectl itself could output colors based on whether it is running in a terminal with color support or not. Like bat itself, which automatically disables color when being executed in things like pipes.

@briantopping
Copy link

kubectl itself could output colors based on whether it is running in a terminal with color support or not

Point taken, but one may want a completely different output for the same basic commands.

@bytebeast
Copy link

bytebeast commented Apr 18, 2024 via email

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 18, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Aug 17, 2024
@ganievs
Copy link

ganievs commented Aug 19, 2024

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl kind/feature Categorizes issue or PR as related to a new feature. priority/P2 sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
Status: Needs Triage
Development

Successfully merging a pull request may close this issue.