Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 92k9s · Kubernetes

Install and use k9s (Kubernetes terminal UI)

k9s is a full-screen terminal UI for Kubernetes: it shows Pods, Deployments, logs, events and resources live, and you jump between them with a few keys — describe, logs, shell, port-forward, scale, restart, delete. For daily cluster work and incidents it is often 5× faster than typing kubectl commands. This guide installs k9s, explains the keys you need, sets a safe configuration (read-only mode for production), and shows the views that find problems fast.

  • 9 Lessen
  • 11 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

92.1

Know it before you install

k9s uses your kubeconfig and your RBAC rights — it can do exactly what kubectl can do as you. You switch views with : commands (:pods, :deploy, :svc, :ns, :ctx …), filter with /, and act on the selected row with keys.

ItemValue
Programk9s (one binary; .rpm/.deb on the releases page)
Config~/.config/k9s/config.yaml (plus aliases.yaml, hotkeys.yaml, skins)
Uses~/.kube/config / $KUBECONFIG
Logsk9s info shows the paths

Commando's in deze les

92.2

Install on RHEL and Ubuntu

Choose the newest release from github.com/derailed/k9s/releases:

curl -fsSLO https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_amd64.tar.gz
tar -xzf k9s_Linux_amd64.tar.gz k9s
install -m 0755 k9s /usr/local/bin/k9s
k9s version
k9s info

(Or install the k9s_linux_amd64.rpm / .deb from the same page.)

92.3

The keys you need

Start it (in a namespace, or read-only):

k9s
k9s -n shop
k9s --context prod --readonly
KeyAction
:pods, :deploy, :svc, :ing, :pvc, :eventsSwitch view (Tab completes).
:ns / :ctxChoose a namespace / a cluster context.
0All namespaces.
/textFilter rows (/!text = not, /-l app=shop = label).
EnterGo into (Deployment → its Pods → containers).
dDescribe.
lLogs (0 tail, w wrap, s autoscroll, p previous container).
sShell into the container.
Shift-fPort-forward.
eEdit the YAML. y shows the YAML.
r (on a Deployment)Rollout restart. s = scale.
Ctrl-d / Ctrl-kDelete / kill (asks first).
Esc / q / :qBack / quit.
?Help for the current view.

Commando's in deze les

92.4

First configuration: safe defaults

~/.config/k9s/config.yaml
k9s:
  refreshRate: 2
  readOnly: false
  noExitOnCtrlC: true
  ui:
    headless: false
    logoless: true
    skin: ""
  logger:
    tail: 200
    buffer: 5000
    sinceSeconds: 300
  skipLatestRevCheck: true

Make production read-only per context (k9s keeps per-cluster settings under its data folder) — or simply always start production with --readonly. Add an alias so the dangerous command is never the default:

echo "alias k9prod='k9s --context prod --readonly'" >> ~/.bashrc
SettingWhy
--readonly / readOnly: trueNo edit, delete or shell — safe for looking at production.
logger.sinceSeconds / tailLogs open fast and show the last minutes, not days.
noExitOnCtrlCA habit Ctrl-c does not close k9s by accident.

Your own shortcuts in aliases.yaml (for example dp: apps/v1/deployments) and hotkeys.yaml (for example Shift-0 → pods).

92.5

Daily use: find problems fast

  • :pods then /CrashLoop or sort by status (Shift-s) and restarts (Shift-r) — broken Pods come to the top.
  • :events sorted by time — the cluster tells you what is wrong (FailedScheduling, BackOff, Unhealthy).
  • On a Pod: d (Events at the bottom) → l → p (previous container logs after a crash).
  • :pulses — a live overview of the cluster health; :xray deploy shop — a tree of a Deployment with its ReplicaSets, Pods, containers, ConfigMaps and Secrets.
  • :node then Enter — which Pods run on a node; Shift-c/Shift-m sort by CPU/memory (needs metrics-server).

Real uses at work:

  • Incident triage: crashing Pods, events, logs and a shell in seconds.
  • Daily checks of deployments, rollouts and resource use.
  • Teaching Kubernetes: you see how objects connect (xray).

92.6

Make it safe

Security checklist:

  • k9s has your rights — use least-privilege RBAC users, not cluster-admin, for daily work.
  • --readonly for production unless you really must change something.
  • Watch the context name in the header before every action (:ctx).
  • Shell sessions and port-forwards are powerful — close them when done.
  • Keep k9s updated (it follows new Kubernetes versions).

92.7

Update and remove

Download the new release and replace the binary. Remove: rm /usr/local/bin/k9s ~/.config/k9s -r.

Commando's in deze les

92.8

Fix common problems

ProblemCauseFix
Boom!! cannot connect to context / no dataKubeconfig or login (token expired).kubectl get nodes first; log in again (aws sso login, az login).
Views are empty or show forbiddenRBAC: no list/watch rights there.Use a namespace you may see; ask for read rights.
CPU/memory columns show n/aNo metrics-server.Install metrics-server in the cluster.
Keys do nothing (edit, delete)Read-only mode.That is the protection; start without --readonly only when needed.
Strange colours or broken linesTerminal type or font.Use a modern terminal; TERM=xterm-256color; try another skin.

92.9

Next steps

1How do you open k9s on production without any risk of changes?
2A Pod restarts again and again. Which keys show why?

d (describe → Events) and l then p (logs of the previous container).

Alle commando's in dit hoofdstuk