-
K9s uses 256 colors terminal mode. On `Nix system make sure TERM is set accordingly.
export TERM=xterm-256color -
In order to issue resource edit commands make sure your EDITOR and KUBE_EDITOR env vars are set.
# Kubectl edit command will use this env var. export KUBE_EDITOR=my_fav_editor
-
K9s prefers recent kubernetes versions ie 1.28+
| k9s | k8s client |
|---|---|
| >= v0.27.0 | 1.26.1 |
| v0.26.7 - v0.26.6 | 1.25.3 |
| v0.26.5 - v0.26.4 | 1.25.1 |
| v0.26.3 - v0.26.1 | 1.24.3 |
| v0.26.0 - v0.25.19 | 1.24.2 |
| v0.25.18 - v0.25.3 | 1.22.3 |
| v0.25.2 - v0.25.0 | 1.22.0 |
| <= v0.24 | 1.21.3 |
# Use default kubeconfig
$ k9s
# Use non-default kubeconfig
$ k9s --kubeconfig /path/to/kubeconfig
# Use non-default context
$ k9s --context fooctx
# Readonly
$ k9s --readonly
## Check info (locations for configuration, logs, screen dumps)
$ k9s infoList a specific resource:
:<resource>: list Resources, e.g. :pod to list all pods.
:<resource> <namespace>: list Resources in a given namespace.
List all available resources / apis:
:aliases or Ctrl-a: list all available aliases and resources.
:crd: list all CRDs.
:apiservices: list all API Serv
/<filter>: regex filter./!<filter>: inverse regex filter./-l <label>: filter by labels./-f <filter>: fuzzy match.
Type :namespace, select the desired namespace by up or down key, press Enter to select.
:ctx: list ctx, then select from the list.:ctx <context>: switch to the specified context.
Type :secrets to list the secrets, then
xto decrypt the secret.Escto leave the decrypted display.
- move up and down without moving your right hand:
j: down.k: up.h: leftl: rightSPACE: 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:Deploymentscreen: scale the number of replicas.Podor Containers screen: shellx: decode a Secret.f: fullscreen. Tip: enter fullscreen mode before copying, to avoid | in copied text. cCtrl-d`: delete.Ctrl-k: kill (no confirmation).Ctrl-w: toggle wide columns. (Equivalent to kubectl ... -o wide)Ctrl-z: toggle error stateCtrl-e: hide header.Ctrl-s: save output (e.g. the YAML) to disk.Ctrl-l: rollback.
Shift-c: sorts by CPU.Shift-m: sorts by MEMORY.Shift-s: sorts by STATUS.Shift-p: sorts by namespace.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: show helm releases.:helm NAMESPACE: show releases in a specific namespace.
There's no "user" object but in k9s you can see all the users by :users. Press Enter to see a list of Policies.
:xray RESOURCE, e.g. :xray deploy.
:pulse:displays general information about the Kubernetes cluster.
:popeyeorpop: checks all resources for conformity with the correctness criteria and displays the resulting "rating" with explanations. https://popeyecli.io
:dir /pathE.g.:dir /tmpwill show your/tmpfolder on local disk. One common use case:Ctrl-sto save a yaml, then find it in:dir /tmp/k9s-screens-root, find the file, presseto edit andato apply.
Esc: Bails out of view/command/filter mode. c:qorCtrl-c`: quit k9s.
Most of the headers are easy to understand; some of the special ones:
%CPU/R: Percentage of requested CPU%CPU/L: Percentage of limited CPU%MEM/R: Percentage of requested memory%MEM/L: Percentage of limited memoryCPU/A: allocatable CPU
Pods:
pf: PortForward
Containers:
PROBES(L:R): Liveness and Readiness probes
Add all kubeconfig paths to $KUBECONFIG, then start k9s:
$ export KUBECONFIG=/path/to/kubeconfig1:/path/to/kubeconfig2:~/.kube/config:$KUBECONFIG
$ k9sInside k9s, type :ctx, then select the context to change to a different cluster.
Go to the Deployments page, and press s, then enter a number for the desired num of ReplicaSet.
Ctrl-d, move cursor to Force, press space to select, click OK.
In k9s, some namespace foo may appear as foo+, the + denotes a favorite namespace,
i.e. it will appear on the header with a number to quickly select the namespace,
e.g. 0 to select all namespaces.
To add + to the namespace: select namespace in the list, press u (for "Use").
The * indicate the default namespace.
Check CPU and MEM usage on the top left corner of the screen;
Check usage in Node and Pod page;
This is equivalent to:
$ kubectl top nodes
$ kubectl top pods
$ kubectl top node <node_name>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.
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: ClusterUse 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/clustersOr go to the CRDs page (:crd), move to the correct row, press enter.
Change ~/.config/k9s/config.yml:
logger:
tail: 500
buffer: 5000
sinceSeconds: -1:event(or:ev): see the stream of events.:pod: see the list of pods Shift-a to sort by age.:job: see the list of jobs, ordered by time by default.
Find the controller that manages the CR, scale it down for deletion.
# Scale down the controllers:
$ kubectl scale --replicas=0 deployment/CONTROLLER_MANAGER_NAME -n NAMESPACE
# Edit the manifest, e.g. changing a field `foo` to true
$ kubectl patch KIND NAME -n NAMESPACE --type=json -p="[{'op': 'replace', 'path': '/spec/foo', 'value': true}]"
# Scale up the controllers:
$ kubectl scale --replicas=1 deployment/CONTROLLER_MANAGER_NAME -n NAMESPACE$ k9s info | grep Logs
Logs: /root/.local/state/k9s/k9s.logk9s 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).
https://github.com/derailed/k9s/tree/master/plugins
# 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