====== k9s Shortcuts ======
Quick reference for navigating and operating a Kubernetes cluster with [[https://k9scli.io|k9s]]. Everything is driven from **command mode** ('':'') to switch resource views; single letters then act on the highlighted row.
===== Launch =====
k9s # default context, all namespaces
k9s -n my-namespace # start in a namespace
k9s --context staging # start in a specific context
k9s --readonly # disable all mutating ops (prod/demos)
k9s -c pods # jump straight to a resource view
k9s --kubeconfig ~/.kube/x # explicit kubeconfig
===== Command mode — resource views =====
Open with '':'' then type a name or alias.
^ View ^ Aliases ^
| Pods | ''po'' |
| Deployments | ''deploy'' ''dp'' |
| Services | ''svc'' |
| Nodes | ''no'' |
| Namespaces | ''ns'' |
| ConfigMaps | ''cm'' |
| Secrets | ''sec'' |
| Ingress | ''ing'' |
| PVCs | ''pvc'' ''pv'' |
| StatefulSets | ''sts'' |
| DaemonSets | ''ds'' |
| Events | ''ev'' |
| CRDs | ''crd'' |
'':ctx'' switches context, '':ns'' switches namespace, '':q'' (or repeated ''Esc'') quits. For CRDs use the kind, or the fully-qualified ''kind.group'' form if the short alias is ambiguous.
===== Navigation =====
^ Key ^ Action ^
| ''↑/↓'' or ''j/k'' | Move between rows |
| ''Enter'' | Drill into the resource (namespace → pods, pod → containers) |
| ''Esc'' | Go back / clear filter / close |
| '':'' | Command mode (switch resource view) |
| ''/'' | Filter rows in the current view |
| ''?'' | Help — all keybindings for the current view |
| ''Ctrl-a'' | List all available resource aliases |
| ''0''–''9'' | Quick-switch namespace by index (0 = all) |
| ''Tab'' / ''Shift-Tab'' | Move between panes |
===== Acting on a resource =====
Highlight a row, then:
^ Key ^ Action ^
| ''d'' | Describe |
| ''l'' | Logs (current container) |
| ''Shift-l'' | Logs (previous / crashed container) |
| ''y'' | View YAML |
| ''e'' | Edit (opens ''$EDITOR'', applies on save) |
| ''s'' | Shell into the pod (exec) |
| ''Ctrl-d'' | Delete (with confirm) |
| ''Ctrl-k'' | Kill (delete, no grace period) |
| ''Shift-f'' | Port-forward |
| ''Enter'' | Drill in (pod → containers, etc.) |
| ''Space'' | Mark / select row (for bulk delete) |
| ''Ctrl-Space'' | Mark a range |
===== Logs =====
From a pod or container, ''l'' opens the log view:
^ Key ^ Action ^
| ''0'' | Tail from the beginning |
| ''1''–''5'' | Last 1 / 5 / 10 / 15 / 30 min (configurable) |
| ''f'' | Toggle full-screen |
| ''w'' | Toggle line wrap |
| ''s'' | Toggle autoscroll |
| ''t'' | Toggle timestamps |
| ''c'' | Copy visible logs to clipboard |
| ''/'' | Filter log lines (regex) |
| ''Esc'' | Back to the resource view |
For multi-container pods, ''Enter'' into the pod first, then ''l'' on the specific container.
===== Filtering & search =====
* ''/text'' — fuzzy filter rows by name
* ''/-l app=foo'' — filter by label selector
* ''/!text'' — inverse filter (hide matches)
* ''Enter'' keeps the filter; ''Esc'' clears it
* Sort columns: ''Shift-c'' (CPU), ''Shift-m'' (mem), ''Shift-n'' (name), ''Shift-a'' (age), ''Shift-s'' (status), ''Shift-r'' (restarts) — press again to reverse
===== Contexts & namespaces =====
:ctx # interactive context switcher
:ctx staging # jump directly
:ns # namespace switcher
''Ctrl-a'' lists every resource alias the current cluster exposes (including CRDs) — fastest way to explore an unfamiliar cluster.
===== Networking =====
There is no single "network" view — networking spans several resource types plus the port-forward machinery.
==== Networking resource views ====
^ Type ^ Aliases ^ Shows ^
| Services | ''svc'' ''service'' | TYPE, CLUSTER-IP, EXTERNAL-IP, PORTS, SELECTOR |
| Endpoints | ''ep'' ''endpoints'' | Backing pod IPs:ports per service |
| EndpointSlices | ''eps'' ''endpointslices'' | Newer endpoint representation |
| Ingress | ''ing'' ''ingress'' | Hosts, paths, backend services, TLS |
| IngressClasses | ''ic'' ''ingressclasses'' | Available ingress controllers |
| NetworkPolicies | ''np'' ''netpol'' | Ingress/egress rules, pod selectors |
| Pods | ''po'' | Already shows IP and NODE columns |
| Nodes | ''no'' | Node internal / external IPs |
If your CNI exposes CRDs they're reachable too — e.g. '':ippools'', '':ciliumendpoints'', '':ciliumnetworkpolicies''. Use ''Ctrl-a'' to list what the cluster actually has.
==== Networking keys ====
^ Key ^ On ^ Action ^
| ''d'' | svc / ing / netpol | Describe — selectors, ports, rules, events |
| ''Enter'' | service | Drill into the endpoints / pods it routes to |
| ''y'' | any | Raw YAML (full spec) |
| ''Shift-f'' | pod / service | Start a port-forward |
| ''s'' | pod | Shell in to run ''ip a'', ''ss -tlnp'', ''nslookup'', ''curl'' |
| ''/'' | any list | Filter; ''/-l app=foo'' filters by label selector |
==== Port-forward & benchmark ====
- Highlight a pod or service → ''Shift-f'' → pick container port, local port, bind address → confirm.
- '':pf'' shows all active forwards. ''Ctrl-d'' cancels one. Forwards die when k9s exits.
- From a forward, ''Ctrl-b'' runs k9s's built-in HTTP load test; results land in '':benchmarks'' ('':be''), where you can view or delete them.
==== Debug flow ====
'':svc'' → ''d'' to confirm the selector and ports → ''Enter'' to verify it has endpoints (empty endpoints = selector mismatch or no ready pods) → '':po'', find a backing pod, ''s'' to shell in and test connectivity from inside the cluster. '':xray svc'' gives a tree of service → endpoints → pods for topology at a glance.
===== Tips =====
* ''--readonly'' (or ''readOnly: true'' in config) is worth defaulting on for any prod-touching context — greys out every mutating key.
* Per-context skins are the best safeguard against acting on the wrong cluster — make prod red.
* ''Ctrl-z'' toggles "wait" mode if the screen looks frozen during heavy refreshes; lowering ''refreshRate'' helps on large clusters.
* If a CRD doesn't show under its short alias, use ''kind.group'' or find it via '':crd''.
* '':pulse'' is a cluster health dashboard; '':xray '' shows a dependency tree.
* ''?'' in **any** view lists the keys valid right there.