Skip to content
Vladimir Chavkov
Go back

K9s: The Ultimate Kubernetes Terminal UI for Cluster Management

Edit page

K9s: The Ultimate Kubernetes Terminal UI for Cluster Management

K9s is a terminal-based UI for managing Kubernetes clusters that provides a fast, efficient alternative to kubectl commands and web dashboards. This comprehensive guide covers everything you need to master K9s for daily Kubernetes operations.

What is K9s?

K9s is an open-source, terminal-based UI that provides:

Key Features

  1. Real-time Monitoring: Live view of cluster resources with auto-refresh
  2. Resource Navigation: Quick navigation between namespaces and resources
  3. Vim-style Shortcuts: Keyboard-driven workflow for power users
  4. Context Switching: Easy switching between clusters and contexts
  5. Built-in Shell: Execute commands directly in pods
  6. Log Streaming: Tail logs from multiple containers
  7. Resource Editing: Edit resources with your preferred editor
  8. Custom Views: Create custom resource views and aliases
  9. Plugins: Extend functionality with custom plugins
  10. Port Forwarding: Manage port forwards from the UI

K9s vs. Other Tools

FeatureK9skubectlLensOctant
InterfaceTerminalCLIDesktop GUIWeb UI
SpeedVery FastFastMediumMedium
Resource UsageMinimalMinimalHighMedium
Offline Mode✅ Yes✅ Yes⚠️ Limited❌ No
Multi-cluster✅ Easy✅ Manual✅ Easy✅ Easy
Customization✅ Extensive⚠️ Limited⚠️ Limited⚠️ Limited
Learning CurveModerateLowLowLow

Installation

macOS

Terminal window
# Using Homebrew
brew install derailed/k9s/k9s
# Upgrade
brew upgrade k9s
# Using MacPorts
sudo port install k9s

Linux

Terminal window
# Download latest release
wget https://github.com/derailed/k9s/releases/download/v0.31.9/k9s_Linux_amd64.tar.gz
# Extract
tar -xzf k9s_Linux_amd64.tar.gz
# Move to PATH
sudo mv k9s /usr/local/bin/
# Verify installation
k9s version
# Using package managers
# Arch Linux
yay -S k9s
# Ubuntu/Debian (via snap)
sudo snap install k9s
# Using go
go install github.com/derailed/k9s@latest

Windows

Terminal window
# Using Scoop
scoop install k9s
# Using Chocolatey
choco install k9s
# Manual installation
# Download from GitHub releases
# Extract and add to PATH

Docker

Terminal window
# Run K9s in Docker
docker run --rm -it \
-v ~/.kube/config:/root/.kube/config \
derailed/k9s

Getting Started

First Launch

Terminal window
# Launch K9s
k9s
# Launch with specific context
k9s --context production-cluster
# Launch with specific namespace
k9s -n production
# Launch in read-only mode
k9s --readonly
# Launch with specific kubeconfig
k9s --kubeconfig ~/.kube/custom-config

Basic Navigation

Navigation Keys:
- :pods → View pods
- :deployments → View deployments
- :services → View services
- :namespaces → View namespaces
- :nodes → View nodes
- Ctrl-a → Show all available resources
- / → Filter resources
- Esc → Clear filter/go back
- Ctrl-d → Delete resource
- Enter → View resource details
- l → View logs
- s → Shell into container
- Ctrl-c → Exit K9s
Resource Navigation:
- j/k or ↓/↑ → Move down/up
- g → Go to top
- Shift-g → Go to bottom
- Ctrl-f → Page down
- Ctrl-b → Page up
- Space → Mark resource
- Ctrl-space → Mark all resources

Essential Commands

Viewing Resources

Terminal window
# In K9s command mode (press :)
:pods # List pods
:po # Short form
:deploy # Deployments
:svc # Services
:ing # Ingresses
:cm # ConfigMaps
:secret # Secrets
:pvc # PersistentVolumeClaims
:nodes # Nodes
:ns # Namespaces
:events # Events
:jobs # Jobs
:cronjobs # CronJobs
:hpa # Horizontal Pod Autoscalers
:psp # Pod Security Policies
# View all resources
Ctrl-a
# View custom resources
:certificates # cert-manager
:issuers # cert-manager
:virtualservices # Istio

Working with Pods

Terminal window
# In pod view
Enter # Describe pod
l # View logs
Ctrl-l # Toggle log auto-scroll
p # Previous logs (from restarted containers)
s # Shell into container
a # Attach to container
f # Port-forward
Ctrl-k # Kill pod (delete)
y # View YAML
e # Edit pod (not common, usually edit deployment)
Shift-f # Toggle show/hide failed pods
# Multi-container pods
l Tab # Switch between container logs
s Select # Choose container for shell

Working with Logs

Terminal window
# Log viewing
l # View logs
Ctrl-l # Toggle auto-scroll
w # Toggle log wrap
t # Toggle timestamp
0-9 # Container selection (multi-container pods)
f # Toggle fullscreen
c # Clear logs
/ # Search in logs (press n for next, N for previous)
s # Save logs to file
# Advanced log options
Shift-l # View logs from previous container instance
Ctrl-r # Toggle raw logs (no formatting)

Filtering and Searching

Terminal window
# Filter current view
/pattern # Filter by pattern
Esc # Clear filter
# Label filters
/app=nginx # Filter by label
/!app=nginx # Inverse filter
# Status filters
/Running # Show only running pods
/Pending # Show pending pods
/Error # Show pods with errors
# Regex filters
/^prod-.* # Pods starting with "prod-"
/.*-db$ # Pods ending with "-db"
# Multiple filters
/label1=value1,label2=value2

Advanced Features

Context and Namespace Management

Terminal window
# Switch context
:ctx # List contexts
Enter # Switch to selected context
# Switch namespace
:ns # List namespaces
Enter # Switch to namespace
0 # Switch to all namespaces
# Quick namespace switch
:ns/production # Jump directly to namespace

Resource Operations

Terminal window
# Describe resource
d # Describe selected resource
Enter # Alternative to describe
# Edit resource
e # Edit with default editor
v # Edit with vim explicitly
# Delete resource
Ctrl-d # Delete selected resource
Ctrl-k # Alternative delete
# Scale deployment
:deploy Select s Enter new count
# Restart deployment
:deploy Select Ctrl-r
# Cordon/Drain nodes
:nodes Select Ctrl-c # Cordon
:nodes Select Ctrl-o # Uncordon
:nodes Select Ctrl-d # Drain

Port Forwarding

Terminal window
# From pod view
f # Port forward
# Enter: local_port:container_port
# Example: 8080:80
# List active port forwards
:pf
# Stop port forward
:pf Select Ctrl-d
# Port forward to service
:svc Select f

Shell Access

Terminal window
# Shell into pod
s # Shell access
# For multi-container pods, select container
# Common shell scenarios
:deploy Select s Select pod Select container
# Execute command
Ctrl-s # Run command in container
# Attach to container
a # Attach (for debugging)

Configuration

Config File Location

Terminal window
# K9s config location
~/.config/k9s/config.yml # Linux/macOS
%APPDATA%\k9s\config.yml # Windows
# View current config
cat ~/.config/k9s/config.yml

Custom Configuration

~/.config/k9s/config.yml
k9s:
# Refresh rate (milliseconds)
refreshRate: 2000
# Max log buffer lines
maxConnRetry: 5
# Enable mouse support
enableMouse: false
# Headless mode
headless: false
# Logo
logoless: false
# Crumbsless
crumbsless: false
# Read-only mode
readOnly: false
# No exit on error
noExitOnError: false
# UI settings
ui:
enableMouse: false
headless: false
logoless: false
crumbsless: false
noIcons: false
# Skip latest version check
skipLatestRevCheck: false
# Disable pod counts
disablePodCounting: false
# Shell pod settings
shellPod:
image: busybox:1.35.0
command: []
args: []
namespace: default
limits:
cpu: 100m
memory: 100Mi
# Image scan settings
imageScans:
enable: true
exclusions:
namespaces: []
labels: {}
# Logger settings
logger:
tail: 100
buffer: 5000
sinceSeconds: -1
fullScreen: false
textWrap: false
showTime: false
# Thresholds
thresholds:
cpu:
critical: 90
warn: 70
memory:
critical: 90
warn: 70

Skin/Theme Configuration

~/.config/k9s/skin.yml
k9s:
# General
body:
fgColor: dodgerblue
bgColor: '#1e1e1e'
logoColor: blue
# Frames
frame:
border:
fgColor: dodgerblue
focusColor: lightskyblue
menu:
fgColor: white
keyColor: pink
numKeyColor: fuchsia
crumbs:
fgColor: white
bgColor: steelblue
activeColor: skyblue
status:
newColor: lightskyblue
modifyColor: greenyellow
addColor: lightskyblue
errorColor: red
highlightColor: orange
killColor: mediumpurple
completedColor: gray
title:
fgColor: white
bgColor: steelblue
highlightColor: orange
counterColor: slateblue
filterColor: slategray
# Views
views:
table:
fgColor: lightskyblue
bgColor: default
cursorColor: steelblue
markColor: darkgoldenrod
xray:
fgColor: lightskyblue
bgColor: default
cursorColor: steelblue
cursorTextColor: black
graphicColor: darkgoldenrod
yaml:
keyColor: steelblue
colonColor: white
valueColor: lightskyblue
logs:
fgColor: lightskyblue
bgColor: default

Aliases

~/.config/k9s/alias.yml
alias:
# Resource aliases
dp: v1/deployments
sec: v1/secrets
ing: extensions/v1beta1/ingresses
svc: v1/services
# Custom shortcuts
pp: v1/pods
pvc: v1/persistentvolumeclaims
pv: v1/persistentvolumes
# Helm
hr: helm.toolkit.fluxcd.io/v2beta1/helmreleases
# Cert-manager
cert: cert-manager.io/v1/certificates
issuer: cert-manager.io/v1/issuers
# Istio
vs: networking.istio.io/v1beta1/virtualservices
dr: networking.istio.io/v1beta1/destinationrules
gw: networking.istio.io/v1beta1/gateways

Plugins

Plugin Configuration

~/.config/k9s/plugin.yml
plugin:
# Debug with ephemeral container
debug:
shortCut: Shift-D
description: Debug
scopes:
- pods
command: kubectl
background: false
args:
- debug
- -it
- -n
- $NAMESPACE
- $NAME
- --image=nicolaka/netshoot
- --target=$NAME
- -- bash
# Dive into container image
dive:
shortCut: d
description: Dive image
scopes:
- containers
command: dive
background: false
args:
- $COL-IMAGE
# Stern for logs
stern:
shortCut: Ctrl-L
description: Stern logs
scopes:
- pods
command: stern
background: false
args:
- --tail
- 50
- -n
- $NAMESPACE
- $NAME
# Get pod logs since time
logs-since:
shortCut: Shift-L
description: Logs 1h
scopes:
- pods
command: kubectl
background: false
args:
- logs
- -n
- $NAMESPACE
- $NAME
- --since=1h
# Top pod
top:
shortCut: Shift-T
description: Top pod
scopes:
- pods
command: kubectl
background: false
args:
- top
- pod
- -n
- $NAMESPACE
- $NAME
# Restart deployment
restart:
shortCut: Shift-R
description: Restart
scopes:
- deployments
command: kubectl
background: false
confirm: true
args:
- rollout
- restart
- deployment
- -n
- $NAMESPACE
- $NAME
# Describe node
node-describe:
shortCut: Shift-D
description: Describe
scopes:
- nodes
command: kubectl
background: false
args:
- describe
- node
- $NAME
# Flux reconcile
flux-reconcile:
shortCut: Shift-R
description: Flux reconcile
scopes:
- helmreleases
command: flux
background: false
args:
- reconcile
- helmrelease
- -n
- $NAMESPACE
- $NAME

Hotkeys and Shortcuts

Global Shortcuts

? or Ctrl-h → Show help
Ctrl-a → Show all resources
Ctrl-c → Exit K9s
: → Command mode
/ → Filter mode
Esc → Back/Clear
Ctrl-r → Refresh
Ctrl-d → Delete resource
Ctrl-k → Kill pod
u → Show UID column

View-Specific Shortcuts

Pods:
l → Logs
p → Previous logs
s → Shell
a → Attach
f → Port forward
Shift-f → Show/hide failed pods
Ctrl-k → Kill pod
y → View YAML
Deployments:
s → Scale
Ctrl-r → Restart rollout
r → Rollout status
Nodes:
Ctrl-c → Cordon
Ctrl-o → Uncordon
Ctrl-d → Drain
y → View YAML
Logs:
w → Toggle wrap
t → Toggle timestamp
f → Toggle fullscreen
c → Clear logs
s → Save logs
0-9 → Container selection

Productivity Tips

Quick Resource Access

Terminal window
# Use command mode for fast access
:po # Pods
:po -n production # Pods in namespace
:deploy/nginx # Specific deployment
:svc/api # Specific service
# Use context/namespace combo
:ctx/prod :ns/api :po

Monitoring Multiple Resources

Terminal window
# Open multiple K9s instances
# Terminal 1: Monitor pods
k9s -n production
# Terminal 2: Monitor nodes
k9s
:nodes
# Terminal 3: Monitor events
k9s
:events
# Use tmux/screen for split view
tmux
Ctrl-b % # Split vertical
k9s # First pane
Ctrl-b o # Switch pane
k9s -n production # Second pane

Common Workflows

Terminal window
# Debug failing pod
:po /status=Error Enter l s
# Scale deployment
:deploy /app=api s Enter new count
# Check resource usage
:nodes Shift-t
:po Select Shift-t
# Port forward to service
:svc /app=database f 5432:5432
# View all resources in namespace
:ns/production Ctrl-a
# Quick log search
:po l /ERROR n (next) → N (previous)

Troubleshooting

Common Issues

Terminal window
# K9s won't start
k9s --version # Check version
k9s info # Show diagnostics
rm -rf ~/.config/k9s/ # Reset config
rm -rf ~/.k9s/ # Remove cache
# Performance issues
# Edit config to increase refresh rate
refreshRate: 5000 # 5 seconds instead of 2
# Disable pod counting
disablePodCounting: true
# Connection issues
kubectl cluster-info # Verify cluster access
k9s --context different-context # Try different context
# RBAC issues
# Check permissions
kubectl auth can-i list pods --all-namespaces
# Use read-only mode if needed
k9s --readonly

Debug Mode

Terminal window
# Enable debug logging
k9s --write --logLevel debug
# View logs
tail -f /tmp/k9s-*.log

Production Best Practices

Security

Terminal window
# Use read-only mode in production
k9s --readonly
# Limit access with RBAC
# Create ServiceAccount with limited permissions
kubectl create sa k9s-viewer
kubectl create clusterrolebinding k9s-viewer \
--clusterrole=view \
--serviceaccount=default:k9s-viewer
# Use that context with K9s
k9s --context k9s-viewer-context

Configuration Management

Terminal window
# Version control K9s config
cd ~/.config/k9s
git init
git add config.yml skin.yml alias.yml plugin.yml
git commit -m "K9s configuration"
# Share config across team
git remote add origin git@github.com:company/k9s-config.git
git push -u origin main

Team Standards

.config/k9s/config.yml
# Shared team config
k9s:
refreshRate: 2000
readOnly: false # Set to true for prod
# Consistent shell pod
shellPod:
image: company/debug-tools:latest
namespace: default
# Standard thresholds
thresholds:
cpu:
critical: 90
warn: 70
memory:
critical: 90
warn: 70

Comparison with kubectl

Terminal window
# kubectl commands → K9s equivalents
# List pods
kubectl get pods :po
kubectl get pods -n prod :ns/prod :po
kubectl get pods -w :po (auto-refresh)
# Describe
kubectl describe pod nginx :po /nginx Enter
# Logs
kubectl logs nginx :po /nginx l
kubectl logs -f nginx :po /nginx l (auto-tail)
# Delete
kubectl delete pod nginx :po /nginx Ctrl-d
# Shell
kubectl exec -it nginx -- sh :po /nginx s
# Port forward
kubectl port-forward svc/api :svc /api f
# Edit
kubectl edit deploy nginx :deploy /nginx e
# Scale
kubectl scale deploy nginx --replicas=3 :deploy /nginx s

Conclusion

K9s transforms Kubernetes cluster management with its efficient, keyboard-driven interface. By mastering K9s shortcuts, plugins, and configuration options, you can dramatically improve your productivity when working with Kubernetes clusters.

The tool’s real-time monitoring, intuitive navigation, and extensibility make it an essential tool for anyone managing Kubernetes clusters, from development to production environments.


Master Kubernetes tools and best practices with our comprehensive Kubernetes training programs. Contact us for customized training designed for your team’s needs.


Edit page
Share this post on:

Previous Post
Helm: Complete Kubernetes Package Manager and Chart Development Guide
Next Post
ZFS Filesystem: Complete Enterprise Storage Guide