Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

k9s

A full-screen terminal UI for Kubernetes: browse resources, read logs, open a shell and delete pods with a few keys.

Level
DevOps tool
Group
Containers and Kubernetes
Needs root
No
Package
k9s

What it does

k9s shows your cluster live in the terminal. Type : and a resource name (:pods, :deploy, :svc, :events) to jump there; / filters; Enter goes inside. It uses your kubeconfig and your RBAC rights, like kubectl.

It is fast for troubleshooting: see a crashing pod, press l for logs, d to describe, s for a shell.

How to write it

k9s [OPTIONS]

Options 17

Most used

Start options

-n, --namespace NS
Start in a namespace.
-A, --all-namespaces
Start with all namespaces.
--context NAME
Use another kubeconfig context.
-c, --command RES
Start in a view (for example -c deploy).
--readonly
No delete, edit or shell (safe on production).
--kubeconfig FILE
Use another kubeconfig.
-l, --logLevel debug
Log level of k9s itself.
info
Show where k9s keeps config and logs.

Keys

: RES
Go to a resource view (pods, deploy, svc, ns, events, ctx).
/ TEXT
Filter the list.
l / p
Logs / previous logs of the pod.
d / y / e
Describe / YAML / edit.
s
Shell into the container.
shift-f
Port-forward.
ctrl-d / ctrl-k
Delete / kill.
0 / 1-9
All namespaces / favourite namespaces.
? / esc / ctrl-c
Help / back / quit.

Examples 11

$ run as a normal user# run as root (or with sudo)

  1. 1Start in a namespace

    k9s -n shop
  2. 2Safe view on production

    k9s --context prod --readonly
  3. 3Start in the Deployments view

    k9s -c deploy -A
  4. 4Find crashing pods

    k9s -n shop -c pods

    Type /Crash to filter, then l for the logs and p for the logs before the restart.

  5. 5Look at events of the namespace

    k9s -n shop -c events

    Sort by age with shift-a.

  6. 6Restart a deployment

    k9s -n shop -c deploy

    Select it, press r (rollout restart).

  7. 7Port-forward to a service

    k9s -n shop -c svc

    Select it, press shift-f and choose the port.

  8. 8Change the context

    k9s -c ctx

    Select the cluster, press Enter.

  9. 9Where are the k9s config and logs?

    k9s info
  10. 10Use another kubeconfig file

    k9s --kubeconfig ~/.kube/lab.yaml
  11. 11Debug a k9s problem

    k9s -l debug
    tail -f "$(k9s info | awk '/Logs/{print $2}')"

Watch out

  • k9s can delete and edit with one key; use --readonly or a read-only RBAC user on production.
  • It shows only what your RBAC allows; missing views often mean missing rights.

Files

~/.config/k9s/
Config, skins, aliases (see k9s info).

Tips to remember

  • Learn kubectl first (exams have no k9s), then use k9s for speed at work.

Exit codes

0Normal exit.
1Error (for example the cluster cannot be reached).

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man k9s