K9s Kubernetes TUI

K9s cheatsheet — navigate Kubernetes clusters with keyboard shortcuts. :pods, :deploy, /filter, d=describe, l=logs, s=shell. Full K9s TUI keyboard reference.

5 min read

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 default namespace. You can switch namespaces using the :ns command or by pressing Shift+N.
  • Resources: K9s displays various Kubernetes resources like Pods, Deployments, Services, etc. You navigate between resource types using their shortcuts (e.g., pods for Pods, deploy for Deployments).
  • Contexts: K9s automatically uses your current kubectl context. You can switch contexts using the :ctx command or Shift+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

  • 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 in READY state.
  • e: Show pods in ERROR state.
  • s: Show pods in SUSPENDED state.
  • d: Show pods in DEBUG state.
  • 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+E or :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:

    p
    

    Then press e to see only errored pods.

  • Stream logs from a specific pod:

    p
    <type pod name to filter>
    Ctrl+L
    

    Then press -f to 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+E
    

    Save 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+M
    

    This toggles resource metrics display.

Gotchas

  • Resource Shortcuts: K9s uses single-letter shortcuts for resources. If you forget them, :h is 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+C vs :delete: Ctrl+C on a resource list often performs a "clean up" action (e.g., deleting completed jobs/pods), while :delete explicitly 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 $EDITOR environment variable for YAML editing. Ensure it’s set to your preferred editor.