Home > OS >  bash, watch command with kubecolor
bash, watch command with kubecolor

Time:09-30

I use kubectl with watch so I can have a "realtime" view of what I'm ding as I'm updating pods and stuff, usually I go like:

watch -n1 kubectl get pods 

Now I want to do the same using kubecolor as the output is much better but the watch command won't display the colors, as I read on the man pages I'm trying:

watch -n1 --color "kubecolor get pods" 

Without any luck, colors are not being displayed :(

Does someone knows how to properly do it ?

CodePudding user response:

The reason is that kubecolor detects that it is running non-interactively. Therefore the problem is not the watch command, but kubecolor itself that disables color output when combined with watch.

If you are using a linux operating system, you can use unbuffer to get the output working as expected. For Debian/Ubuntu instll the expect package to get unbuffer.

The command to be used could then look as this:

watch -c unbuffer kubecolor get pods

In addition to that kubectl (and kubecolor) support the --watch switch itself. Does not solve all use cases, but since it uses the API server watch method it is more efficient.

  • Related