Start with K9s
Use default config
$ k9s
Use non-default kubeconfig
$ k9s --kubeconfig /path/to/kubeconfig
Use non-default context
$ k9s --context fooctx
Readonly
$ k9s --readonly
Check info (locations for configurations, logs, screen dumps)
$ k9s info
Use K9s
List Resources
List a specific resource:
:<resource>: list Resources, e.g.:podto list all pods.:<resource> <namespace>: list Resources in a given namespace.
List all available resources:
:aliasesor Ctrl-a : List all available aliases and resources.:crd: list all CRDs.
Filter
/<filter>: regex filter./!<filter>: inverse regex filter./-l <label>: filter by labels./-f <filter>: fuzzy match.
Choose namespace
Type :namespace, select the desired namespace by up or down key, press Enter to select.
Choose context
:ctx: list ctx, then select from the list.:ctx <context>: swtich to the specified context.
Show Decrypted Secrets
Type :secrets to list the secrets, then
- x to decrypt the secret.
- Esc to leave the decrypted display.
Key mapping
- move up and down without moving your right hand:
- j : down.
- k : up.
- SPACE : select multiple lines (e.g. then Ctrl-d to delete)
- y : yaml.
- d : describe.
- v : view.
- e : edit.
- l : logs.
- w : wrap.
- r : auto-refresh.
- s : scale the number of replicas.
- x : decode a Secret.
- f : fullscreen. Tip: enter fullscreen mode before copying, to avoid | in copied text.
- Ctrl-d : delete.
- Ctrl-k : kill (no confirmation).
- Ctrl-w : toggle wide columns. (Equivalent to kubectl … -o wide)
- Ctrl-z : toggle error state
- Ctrl-e : hide header.
- Ctrl-s : save output (e.g. the YAML) to disk.
- Ctrl-l : rollback.
Sort by Column
- Shift-c : sorts by CPU.
- Shift-m : sorts by MEMORY.
- Shift-s : sorts by STATUS.
- Shift-n : sorts by name;
- Shift-o : sorts by node;
- Shift-i : sorts by IP address;
- Shift-a : sorts by container age;
- Shift-t : sorts by number of restarts;
- Shift-r : sorts by pod readiness;
Helm
:helm: show helm releases.:helm NAMESPACE: show releases in a specific namespace.
XRay View
:xray RESOURCE, e.g. :xray deploy.
Pulse View
:pulse : displays general information about the Kubernetes cluster.
Popeye View
:popeye or pop: checks all resources for conformity with the correctness criteria and displays the resulting “rating” with explanations. https://popeyecli.io
Show Disk Files
:dir /path
E.g. :dir /tmp will show your /tmp folder on local disk. One common use case: Ctrl-s to save a yaml, then find it in :dir /tmp/k9s-screens-root, find the file, press e to edit and a to apply.
Quit
Esc : Bails out of view/command/filter mode. : q or Ctrl-c : quit k9s.
Tips
:event(orev): see the strem of events.:pod:job
Meaning of the Header
%CPU/R: Percentage of requested cpu%CPU/L: Percentage of limited cpu%MEM/R: Percentage of requested memory%MEM/L: Percentage of limited memory
K9s warnings
E.g memory level warning, to check CPU/Memory usages:
$ kubectl top nodes
$ kubectl top pods
Benchmark
k9s includes a basic HTTP load generator.
To enable it, you have to configure port forwarding in the pod. Select the pod and press SHIFT+f, go to the port-forward menu (using the pf alias).
After selecting the port and hitting CTRL+b, the benchmark would start. Its results are saved in /tmp for subsequent analysis.
To change the configuration of the benchmark, create the $HOME/.k9s/bench-<my_context>.yml file (unique for each cluster).
Configure K9s
Note that all YAML files in the .k9s directory must have the .yml extension (.yaml doesn’t work).
$HOME/.k9s/views.yml: customize the column view for resource lists.$HOME/.k9s/plugin.yml: manage plugins.$XDG_CONFIG_HOME/k9s/config.yml: k9s config.$XDG_CONFIG_HOME/k9s/alias.yml: define your own alias.$XDG_CONFIG_HOME/k9s/hotkey.yml: define your own hotkeys.$XDG_CONFIG_HOME/k9s/plugin.yml: manage plugins.
Check Resources with the Same Name in Different API Groups
e.g. Cluster may be found in different api groups, like cluster.x-k8s.io or clusterregistry.k8s.io or baremetal.cluster.gke.io.
apiVersion: cluster.x-k8s.io/v1alpha3
kind: Cluster
apiVersion: clusterregistry.k8s.io/v1alpha1
kind: Cluster
apiVersion: baremetal.cluster.gke.io/v1
kind: Cluster
Use apiVersion / kind (i.e. Group / Version / kind) instead of just kind to check the API of a specific group.
:cluster.x-k8s.io/v1alpha3/clusters:clusterregistry.k8s.io/v1alpha1/clusters:baremetal.cluster.gke.io/v1/clusters
Change log setting
Change ~/.config/k9s/config.yml :
logger:
tail: 500
buffer: 5000
sinceSeconds: -1
Plugins
Install
# Go
$ go install github.com/derailed/k9s@latest
# Homebrew / LinuxBrew
$ brew install derailed/k9s/k9s
# MacPort
sudo port install k9s
# Snap
sudo snap install k9s
# PacMan
pacman -S k9s
# Windows: scoop
scoop install k9s
# Windows: chocolatey
choco install k9s