What it is
K9s is a terminal-based UI that helps you manage your Kubernetes clusters. You reach for it when you want a quick, interactive overview and way to navigate your cluster resources without constantly typing kubectl commands.
Installation
Linux
wget -q https://github.com/derailed/k9s/releases/download/v0.31.7/k9s_0.31.7_Linux_x86_64.deb
sudo dpkg -i k9s_0.31.7_Linux_x86_64.deb
rm k9s_0.31.7_Linux_x86_64.deb
Or using Homebrew:
brew install derailed/k9s/k9s
Mac
brew install derailed/k9s/k9s
Windows
Download the appropriate .exe file from the k9s releases page and add it to your system’s PATH.
Core Concepts
- Namespaces: K9s defaults to the
defaultnamespace. You can switch namespaces using the:nscommand or by pressingShift+N. - Resources: K9s displays various Kubernetes resources like Pods, Deployments, Services, etc. You navigate between resource types using their shortcuts (e.g.,
podsfor Pods,deployfor Deployments). - Contexts: K9s automatically uses your current
kubectlcontext. You can switch contexts using the:ctxcommand orShift+C. - Filters: You can filter resources by name or labels directly from the resource list screen.
- Key Bindings: K9s is heavily reliant on keyboard shortcuts for navigation and actions.
Commands / Usage
Navigating the UI
Ctrl+P: Previous screen/resource.Ctrl+N: Next screen/resource.Ctrl+C: Return to the main dashboard.Ctrl+R: Refresh the current screen.Ctrl+L: Clear the command buffer.Ctrl+F: Toggle filter mode.Shift+N: Switch namespace.Shift+C: Switch context.:ns <namespace-name>: Directly switch to a specific namespace.:ctx <context-name>: Directly switch to a specific context.:h: Show help screen with all key bindings.
Main Dashboard (:)
:d: Show dashboard.:diag: Run diagnostic checks.:version: Show k9s version information.:restart: Restart k9s.:shell: Open a shell in the current pod.:env: View environment variables for the current pod.:logs: View logs for the current pod.:portforward <local-port>:<pod-port>: Port forward to a pod.:describe: View the YAML description of the current resource.:yaml: Edit the YAML of the current resource.:edit: Edit the YAML of the current resource.:delete: Delete the current resource.:toast <message>: Display a temporary message.
Resource Views (e.g., Pods)
Pressing the resource shortcut key (e.g., p for pods) will bring you to that resource list.
Pods (p)
a: Show all pods (across all namespaces).o: Show pods inREADYstate.e: Show pods inERRORstate.s: Show pods inSUSPENDEDstate.d: Show pods inDEBUGstate.Ctrl+D: Delete selected pod(s).Ctrl+E: Edit pod.Ctrl+L: View logs for selected pod(s).Ctrl+S: Shell into selected pod.Ctrl+P: Port-forward to selected pod.Ctrl+C: Clean up selected pod(s) (e.g., delete completed pods).:logs -f: Stream logs for the selected pod.:logs <pod-name>: View logs for a specific pod.:exec -it <pod-name> -- <command>: Execute a command in a pod.
Deployments (d)
r: Rollout history for the deployment.Ctrl+U: Undo last rollout.Ctrl+R: Restart deployment.Ctrl+D: Delete deployment.Ctrl+E: Edit deployment.
Services (s)
Ctrl+D: Delete service.Ctrl+E: Edit service.Ctrl+P: Port-forward to service.
StatefulSets (sts)
Ctrl+D: Delete StatefulSet.Ctrl+E: Edit StatefulSet.
DaemonSets (ds)
Ctrl+D: Delete DaemonSet.Ctrl+E: Edit DaemonSet.
Jobs (j)
Ctrl+D: Delete Job.Ctrl+E: Edit Job.Ctrl+R: Restart Job.
CronJobs (cj)
Ctrl+D: Delete CronJob.Ctrl+E: Edit CronJob.Ctrl+R: Activate/Run CronJob.
ConfigMaps (cm)
Ctrl+D: Delete ConfigMap.Ctrl+E: Edit ConfigMap.
Secrets (sec)
Ctrl+D: Delete Secret.Ctrl+E: Edit Secret.Ctrl+V: View secret values.
Nodes (n)
Ctrl+D: Drain node.Ctrl+C: Cordon/Uncordon node.Ctrl+E: Edit node.
Namespaces (ns)
Ctrl+D: Delete namespace.Ctrl+E: Edit namespace.
Filtering and Searching
- In any resource list, start typing to filter by name.
:l <label-selector>: Filter resources by label selector (e.g.,:l app=nginx).:n <namespace>: Filter by namespace.
Editing Resources
Ctrl+Eor:edit: Opens the YAML definition of the selected resource in your configured editor. After saving and closing the editor, k9s will prompt you to apply the changes.
Viewing Logs
Ctrl+L: Shows logs for the selected pod.:logs -f: Streams logs for the selected pod.
Shelling into Pods
Ctrl+S: Opens a shell in the selected pod.:shell: Opens a shell in the current pod.
Port Forwarding
Ctrl+P: Opens a port-forwarding dialog for the selected pod.:portforward <local-port>:<pod-port>: Manually start a port-forward.
Common Patterns
-
Quickly check pod status:
pThen press
eto see only errored pods. -
Stream logs from a specific pod:
p <type pod name to filter> Ctrl+LThen press
-fto stream. -
Delete all pods with a specific label:
p :l app=my-app Ctrl+D(Be careful with this!)
-
Access a web service locally:
s <type service name to filter> Ctrl+P <local-port>:<service-port>Example:
Ctrl+P 8080:80 -
View and edit a deployment’s YAML:
d <type deployment name to filter> Ctrl+ESave and exit the editor, then confirm the apply.
-
Restart a deployment:
d <type deployment name to filter> Ctrl+R -
Check resource usage for pods:
p Ctrl+MThis toggles resource metrics display.
Gotchas
- Resource Shortcuts: K9s uses single-letter shortcuts for resources. If you forget them,
:his your friend. - Context/Namespace Switching: It’s easy to forget which context or namespace you’re in. Keep an eye on the top status bar.
- Apply Changes: When editing YAML, k9s will prompt you to apply changes. Make sure you understand the implications before confirming.
Ctrl+Cvs:delete:Ctrl+Con a resource list often performs a "clean up" action (e.g., deleting completed jobs/pods), while:deleteexplicitly deletes the resource.- Resource Filtering: The filter bar at the top is case-sensitive for names but not for label selectors.
- Editor Configuration: K9s uses your
$EDITORenvironment variable for YAML editing. Ensure it’s set to your preferred editor.