How to Install and Use K9s in Linux Terminal to Manage Kubernetes Clusters

Administering Kubernetes clusters through the standard kubectl command-line client often feels cumbersome. Checking pod health, reviewing deployment replica sets, streaming container logs, and forwarding ports typically requires chaining long commands like kubectl get pods -n production, memorising dynamic pod hashes, and switching between multiple terminal tabs. k9s is a terminal user interface (TUI) for Kubernetes that streamlines cluster management into an interactive, high-speed console.

Written in Go, k9s interacts directly with your cluster’s Kubernetes API server using your active ~/.kube/config contexts. It continuously tracks cluster events, rendering active pods, services, deployments, configmaps, and nodes in real time. With single keystroke controls to stream logs, shell into running containers, view resource usage benchmarks, and trigger rolling restarts, k9s is an essential companion for DevOps engineers and developers. In this guide, you will learn how to install k9s on Linux, navigate cluster namespaces, inspect pod logs, and execute administrative actions directly inside your terminal.

Why Use K9s for Kubernetes Administration?

k9s transforms terminal Kubernetes operations into an intuitive visual workflow:

  • Real-Time Cluster Telemetry: Continuously monitors pod statuses, restarts, CPU allocations, and memory footprints without manual polling.
  • Lightning-Fast Navigation: Jump between namespaces, pod logs, and cluster custom resource definitions (CRDs) with simple keyboard commands.
  • Direct Shell and Log Access: Press s to drop into a pod’s interactive shell or press l to stream colored real-time container logs.
  • Port Forwarding Management: Establish, inspect, and terminate local port forwards with dedicated keyboard shortcuts instead of background process scripts.
  • Cluster Benchmarking & Pulses: View cluster-wide health scores and resource quotas at a single glance with the integrated Pulse view.

Installing K9s on Linux

k9s provides multiple installation pathways across modern Linux distributions:

Method 1: Installing via Pre-Compiled Static Binary

Downloading the pre-compiled binary is universal across all Linux distributions:

  1. Download the latest Linux 64-bit release tarball from GitHub:
    curl -sS https://webi.sh/k9s | sh
  2. Alternatively, download the release archive manually using curl:
    curl -LO https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_amd64.tar.gz
  3. Extract the binary:
    tar -xzf k9s_Linux_amd64.tar.gz
  4. Move the executable to your system path:
    sudo mv k9s /usr/local/bin/
  5. Verify the installation:
    k9s version

Method 2: Installing via Package Managers

For native package management:

  • Ubuntu / Debian (Snap):
    sudo snap install k9s --classic
  • Arch Linux:
    sudo pacman -S k9s
  • Fedora / RHEL:
    sudo dnf install k9s
  • Homebrew on Linux:
    brew install derailed/k9s/k9s

Connecting and Navigating Clusters in K9s

Launch k9s by typing its command in your terminal. It automatically reads your default kubeconfig file (~/.kube/config):

k9s

To connect to a specific cluster context or namespace directly:

k9s --context my-cluster-context -n production

Essential Navigation Commands in K9s

Key Command Action / Navigation Destination
: (Colon) Enter command mode to switch resource views (e.g., :pods, :deploy, :svc, :nodes).
/ (Slash) Search and filter resources by name in the active view.
Enter Drill down into child resources (e.g., inspect containers inside a highlighted pod).
Esc Go back up one level or dismiss modal dialogs.
l View and stream live logs for the highlighted pod.
s Open an interactive shell session (sh / bash) inside the highlighted container.
d Describe the highlighted resource (equivalent to kubectl describe).
e Edit the live resource manifest directly in your default terminal text editor.
Ctrl + d Delete or kill the highlighted pod/deployment with confirmation.
:quit or Ctrl + c Exit k9s cleanly.

Streaming Logs and Port Forwarding

k9s excels at eliminating repetitive troubleshooting sequences during development:

1. Streaming and Filtering Pod Logs

  1. Highlight any running pod in the pod view and press l.
  2. k9s streams live output. Press 0 through 9 to switch between containers if the pod runs multi-container sidecars.
  3. Press / while in the log view to search for specific error exceptions or stack traces.
  4. Press t to toggle log timestamps on or off.
  5. Press w to toggle word-wrapping for long JSON log payloads.

2. Establishing Port Forwards

  1. Highlight a pod or service exposing a web port (e.g., port 8080).
  2. Press Shift + f to open the port forward dialogue.
  3. Specify your desired local port (e.g., 3000).
  4. Press Enter to establish the forwarding tunnel.
  5. Type :portforward to view all active port forwards and manage connections in a single dashboard.

Tips for Efficient Kubernetes Operations

To maximize your productivity when operating clusters with k9s:

  • Switch Namespaces Rapidly: Type :ns, press Enter, and select a namespace to scope your view, or press 0 in the main pod view to view all cluster namespaces simultaneously.
  • Run in Read-Only Mode: When connecting to production environments where accidental deletions must be prevented, launch k9s with the read-only flag:
    k9s --readonly
  • Customise Skin and Themes: Create a custom YAML skin file at ~/.config/k9s/skins/nord.yaml to match your terminal emulator’s corporate color scheme.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.