Kubernetes - Tools, Tips & Tricks
k9s
k9s: ../Kubernetes CLI To Manage Your Clusters In Style!
Usage
When first opened, k9s
show the list of pods.
From the Pods
view, you can:
-
Change the selected pod (
Up
,Down
),- then doing actions with that selected pod (by pressing the key bindings in blue color), e.g.
Describe
that pod, by pressingd
Logs
, show logs of all containers of that pod, by pressingl
- …
- View that selected pod, by pressing
Enter
- then doing actions with that selected pod (by pressing the key bindings in blue color), e.g.
-
Change the namespace (by pressing the key bindings in pink color)
- to
all
by pressing0
- to
default
by pressing1
(by default,k9s
usedefault
namespace)
- to
-
Change to another list (resource)
- List all the resources, by pressing
Ctrl +A
- Change to the view for that resource, by pressing
Enter
for example: change back to the default view -
Pods
Ctrl + A
Down
s to selectpods
(the 2nd one)Enter
- Press
:
to entercommand mode
- Type in the command for pod:
pod
(or any ofpo,pod,pods,v1/pods
- showed inCtrl + A
)
- Type in the command for pod:
- List all the resources, by pressing
Action | Key Binding | Command | Note |
---|---|---|---|
Change the selected resource | Up - Down | ||
View (the selected resource) | Enter | Available for any selected resource | |
Back | Esc | ||
Quit K9s | Ctrl + C | ||
Help | ? | Available at any view, change depend on which view is showing | |
Show all available resource alias | Ctrl + A | 1. Up /Down ; 2. Enter (to close the Aliases view: use Ese or press Ctrl + A again) |
Headlamp
Headlamp1 (a CNCF Sandbox project2): A Kubernetes web UI that is fully-featured, user-friendly and extensible
Tips & Tricks
Use the right version of kubectl
for each cluster/project with asdf
You must use a kubectl
version that is compatible with your cluster control plane (kube-apiserver
).
Why
kubectl
is supported within one minor version (older or newer) of kube-apiserver
.
e.g.
kube-apiserver
is at 1.30kubectl
is supported at 1.31, 1.30, and 1.29
For more information, see
How?
See the demo at asdf-demo repository
Make aliases for kubectl
-
Just a simple alias
k
forkubectl
-
For zsh
alias k="kubectl"
-
-
Use shell plugin that provides a lot of aliases, e.g.
-
oh-my-zsh’s plugin kubectl Some useful aliases the plugin adds:
k
,kaf
,kga
. For the full lists, see kubectl.plugin.zsh | ohmyzsh. -
If you want more, kubectl-aliases add 800 aliases, see the full lists and the syntax explanation
-
Show cluster information in shell prompt
-
oh-my-zsh plugin kubectx
-
Use starship prompt, with its command for Kubernetes
-
Use fish shell, which show it by default
Add shell completions for kubectl
Configuration for completion
-
kubectl completion | kubectl Commands
-
for macOS: https://kubernetes.io/docs/tasks/tools/install-kubectl-macos/#enable-shell-autocompletion
-
for linux: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#enable-shell-autocompletion
-
for windows: https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/#enable-shell-autocompletion
-
Add color to kubectl
output with kubecolor
kubecolor colorizes your kubectl
command output and does nothing else.
You can use kubecolor
as a complete alternative of kubect
Configuration
-
zsh
# .zshrc alias k="kubectl" if [ "$(command -v kubecolor)" ]; then alias kubectl="kubecolor" compdef kubecolor=kubectl fi
-
fish
# ~/.config/fish/config.fish if status is-interactive abbr --add k kubectl # https://fishshell.com/docs/current/cmds/abbr.html if command -v kubecolor &>/dev/null alias kubectl=kubecolor # https://fishshell.com/docs/current/cmds/alias.html # make kubecolor inherit completions from kubectl # https://fishshell.com/docs/current/cmds/complete.html complete -c kubecolor -w kubectl end end
Switch between contexts (cluster) with kubectx
kubectx: ../a tool to switch between contexts (clusters) on kubectl
faster.
Switch between namespaces with kubens
kubens: ../a tool to switch between Kubernetes namespaces (and configure them for kubectl
) easily.
Switch between contexts/namspace with kubeswitch
kubeswitch: ../kubectx for operators, treat clusters as cattle, not pets.