Kubectl klock
A kubectl plugin to render watch output in a more readable fashion
A `kubectl` plugin to render the `kubectl get pods --watch` output in a much more readable fashion. The project is written primarily in Go, distributed under the GNU General Public License v3.0 license, first published in 2022. Key topics include: go, go-cli, golang, golang-cli, hacktoberfest.
kubectl-klock

A kubectl plugin to render the kubectl get pods --watch output in a
much more readable fashion.
Think of it as running watch kubectl get pods, but instead of polling,
it uses the regular watch feature to stream updates as soon as they occur.
Installation
Krew
shkubectl krew install klock
Snap
shsudo snap install klock
Scoop
pwshscoop bucket add applejag https://github.com/applejag/applejag-bucket scoop install applejag/kubectl-klock
Nix
shnix-shell -p kubectl-klock
Pre-built binaries
You can download pre-built binaries from the latest GitHub release: https://github.com/applejag/kubectl-klock/releases/latest
Download the one that fits your OS and architecture, extract the
tarball/zip file, and move the kubectl-klock binary to somewhere in your PATH.
For example:
shtar -xzf kubectl-klock_linux_amd64.tar.gz sudo mv ./kubectl-klock /usr/local/bin
From source
Requires Go 1.21 (or later).
shgo install github.com/applejag/kubectl-klock@latest
Usage
Supports a wide range of flags
shkubectl klock <resource> [name(s)] [flags]
Examples
sh# Watch all pods kubectl klock pods # Watch all pods with more information (such as node name) kubectl klock pods -o wide # Watch a specific pod kubectl klock pods my-pod-7d68885db5-6dfst # Watch a subset of pods, filtering on labels kubectl klock pods --selector app=my-app kubectl klock pods -l app=my-app # Watch all pods in all namespaces kubectl klock pods --all-namespaces kubectl klock pods -A # Watch other resource types kubectl klock cronjobs kubectl klock deployments kubectl klock statefulsets kubectl klock nodes # Watch all pods, but restart the watch when your ~/.kube/config file changes, # such as when using "kubectl config use-context NAME" kubectl klock pods --watch-kubeconfig kubectl klock pods -W
There's also some hotkeys available:
text→/l/pgdn next page / filter by text ctrl+c quit ←/h/pgup prev page enter close the filter input field ?/esc close help g/home go to start esc clear the applied filter d show all deleted G/end go to end ↓/ctrl+n show next suggestion f toggle fullscreen ↑/ctrl+p show previous suggestion tab accept a suggestion
Features
-
Pagination, for when the terminal window gets too small (height-wise)
-
Same output format as
kubectl get -
Watch arbitrary resources, just like
kubectl get <resource> [name] -
Filter results
-
Auto updating age column.
-
Colors on statuses (e.g
Running) and fractions (e.g1/1) to make
them stand out more. -
Restart watch when kubeconfig file changes (flag:
--watch-kubeconfig,-W),
such as when changed by kubectx. -
Color themes powered by kubecolor
-
Shows deleted table rows for a short duration,
controllable via the--hide-deleted=10sflag
andKLOCK_HIDE_DELETED=10senvironment variable.
Can be disabled to always show deleted rows by setting--hide-deleted=false
Environment variables
Command-line flags can be controlled via environment variables:
bashexport KLOCK_ALL_NAMESPACES="true" # --all-namespaces export KLOCK_FIELD_SELECTOR="status.phase!=Succeeded" # --field-separator export KLOCK_HIDE_DELETED="false" # --hide-deleted export KLOCK_LABEL_COLUMNS="app.kubernetes.io/name" # --label-columns export KLOCK_OUTPUT="wide" # --output export KLOCK_SELECTOR="team!=frontend" # --selector export KLOCK_WATCH_KUBECONFIG="true" # --watch-kubeconfig
The command-line flags have precedence over the environment variables.
So if you set KLOCK_ALL_NAMESPACES=true then you can revert the value
by passing the flag --all-namespaces=false
Color themes
Klock uses kubecolor's coloring logic and behavior when coloring its output.
See: https://kubecolor.github.io/customizing/themes/
[!NOTE]
If you have a light background, then switchkubectl-klockto use the light
theme by setting theKUBECOLOR_PRESET=light
environment variable:bashexport KUBECOLOR_PRESET="light" kubectl klock --help
Color settings that klock uses:
KUBECOLOR_THEME_BASE_DANGERfor rows with errorsKUBECOLOR_THEME_BASE_MUTEDfor "No resources found"KUBECOLOR_THEME_BASE_MUTEDfor deleted rowsKUBECOLOR_THEME_BASE_MUTEDfor status lineKUBECOLOR_THEME_BASE_SECONDARYfor "FILTER:" promptKUBECOLOR_THEME_BASE_WARNINGfor "No resources visible" when filteringKUBECOLOR_THEME_DATA_DURATIONFRESHforAGE: 12hwhen below thresholdKUBECOLOR_THEME_DATA_RATIO_EQUALforREADY: 1/1KUBECOLOR_THEME_DATA_RATIO_UNEQUALforREADY: 0/1KUBECOLOR_THEME_STATUS_ERRORforSTATUS: CrashLoopBackOffKUBECOLOR_THEME_STATUS_SUCCESSforSTATUS: RunningKUBECOLOR_THEME_STATUS_WARNINGforSTATUS: TerminatingKUBECOLOR_THEME_TABLE_COLUMNSfor table columnsKUBECOLOR_THEME_TABLE_HEADERfor table header
You can configure these colors either via
environment variables
or via the ~/.kube/color.yaml config file
Completion
To get completion when writing kubectl klock, you need to add
./bin/kubectl_complete-klock
to your PATH.
For example:
shsudo curl https://github.com/applejag/kubectl-klock/raw/main/bin/kubectl_complete-klock -o /usr/local/bin/kubectl_complete-klock sudo chmod +x /usr/local/bin/kubectl_complete-klock
Contributors
Showing top 6 contributors by commit count.
