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
sto drop into a pod’s interactive shell or presslto 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:
- Download the latest Linux 64-bit release tarball from GitHub:
curl -sS https://webi.sh/k9s | sh - Alternatively, download the release archive manually using
curl:curl -LO https://github.com/derailed/k9s/releases/latest/download/k9s_Linux_amd64.tar.gz - Extract the binary:
tar -xzf k9s_Linux_amd64.tar.gz - Move the executable to your system path:
sudo mv k9s /usr/local/bin/ - 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
- Highlight any running pod in the pod view and press
l. - k9s streams live output. Press
0through9to switch between containers if the pod runs multi-container sidecars. - Press
/while in the log view to search for specific error exceptions or stack traces. - Press
tto toggle log timestamps on or off. - Press
wto toggle word-wrapping for long JSON log payloads.
2. Establishing Port Forwards
- Highlight a pod or service exposing a web port (e.g., port 8080).
- Press
Shift + fto open the port forward dialogue. - Specify your desired local port (e.g.,
3000). - Press
Enterto establish the forwarding tunnel. - Type
:portforwardto 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, pressEnter, and select a namespace to scope your view, or press0in 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.yamlto match your terminal emulator’s corporate color scheme.