k9s Terminal UI
k9s provides a terminal-based UI for Kubernetes cluster management with real-time updates and keyboard-driven navigation.
Launch Options
k9s # Default kubeconfig
k9s --kubeconfig /path/to/config # Specific kubeconfig
k9s --context <context-name> # Specific context
k9s -n <namespace> # Start in namespace
k9s --readonly # Read-only mode (no modifications)
k9s --headless # No splash screen
k9s -c <resource> # Start with resource view (e.g., k9s -c pods)
k9s info # Show config/log locations
Navigation Commands (: prefix)
Resource Views
| Command | Resource |
|---------|----------|
| :pod / :po | Pods |
| :deploy / :dp | Deployments |
| :svc | Services |
| :ns | Namespaces |
| :node / :no | Nodes |
| :rs | ReplicaSets |
| :ds | DaemonSets |
| :sts | StatefulSets |
| :cm | ConfigMaps |
| :secret / :sec | Secrets |
| :pvc | PersistentVolumeClaims |
| :pv | PersistentVolumes |
| :ing | Ingresses |
| :cj | CronJobs |
| :job | Jobs |
| :hpa | HorizontalPodAutoscalers |
| :ep | Endpoints |
| :sa | ServiceAccounts |
| :ctx | Contexts |
| :event / :ev | Events |
Special Commands
| Command | Action |
|---------|--------|
| :aliases | Show all resource aliases |
| :xray <resource> | Tree view of resource dependencies |
| :pulse | Cluster health pulse view |
| :popeye | Run cluster linter (if installed) |
| :dir <path> | Browse saved files |
| :q / :quit | Exit k9s |
Global Keyboard Shortcuts
| Key | Action |
|-----|--------|
| ? | Help / Show all shortcuts |
| Esc | Back / Cancel / Exit mode |
| Ctrl+a | Show all resources in namespace |
| Ctrl+e | Toggle header |
| Ctrl+w | Toggle wide columns |
| Ctrl+s | Save resource YAML to file |
| / | Filter mode (regex search) |
| 0-9 | Quick namespace switch (favorites) |
Resource-Specific Actions
Pods
| Key | Action |
|-----|--------|
| l | View logs |
| p | View previous container logs |
| s | Shell into container |
| a | Attach to container |
| d | Describe |
| y | View YAML |
| e | Edit |
| Ctrl+d | Delete |
| Ctrl+k | Kill (force delete) |
| f | Port forward |
| Shift+f | Port forward menu |
Deployments
| Key | Action |
|-----|--------|
| s | Scale replicas |
| r | Restart (rollout restart) |
| d | Describe |
| y | View YAML |
| e | Edit |
| Ctrl+l | Rollback |
General Resources
| Key | Action |
|-----|--------|
| Enter | Select / View details |
| d | Describe |
| y | View YAML |
| e | Edit (opens $EDITOR) |
| Ctrl+d | Delete (with confirmation) |
| Ctrl+k | Kill (no confirmation) |
Sorting
| Key | Sort By |
|-----|---------|
| Shift+c | CPU |
| Shift+m | Memory |
| Shift+s | Status |
| Shift+p | Namespace |
| Shift+n | Name |
| Shift+o | Node |
| Shift+i | IP Address |
| Shift+a | Age |
Filtering & Search
/ # Enter filter mode
/<term> # Filter by term (regex)
/-f <term> # Fuzzy search
/!<term> # Inverse filter (exclude)
/-l app=nginx # Filter by label
Esc # Clear filter
Namespace Operations
| Key/Command | Action |
|-------------|--------|
| :ns | List namespaces |
| u | Mark as favorite (adds +) |
| 0-9 | Quick switch to favorite |
| Enter | Switch to namespace |
Favorites appear in header for quick access.
Logs View
Within pod logs (l):
| Key | Action |
|-----|--------|
| 0 | Tail all containers |
| 1-9 | Tail specific container |
| w | Toggle wrap |
| t | Toggle timestamps |
| s | Toggle auto-scroll |
| / | Search in logs |
| Ctrl+s | Save logs to file |
| m | Mark current position |
| Ctrl+b | Page up |
| Ctrl+f | Page down |
Port Forwarding
After selecting a pod and pressing Shift+f:
- Select container/port
- Enter local port
- Port forward starts in background
- View active forwards:
:pf
Configuration
Config Location
~/.config/k9s/config.yaml # Main config (Linux)
~/Library/Application Support/k9s/config.yaml # macOS
Key Settings
k9s:
refreshRate: 2 # Refresh interval (seconds)
maxConnRetry: 5
readOnly: false # Disable modifications
ui:
enableMouse: false
headless: false # Hide header
logoless: false # Hide logo
crumbsless: false # Hide breadcrumbs
logger:
tail: 1000 # Log lines to keep
buffer: 5000
sinceSeconds: -1 # -1 = all logs
Custom Views
~/.config/k9s/views.yaml:
k9s:
views:
v1/pods:
sortColumn: AGE:desc
columns:
- AGE
- NAMESPACE
- NAME
- STATUS
- RESTARTS
- CPU
- MEM
- IP
- NODE
Skins/Themes
~/.config/k9s/skins/<name>.yaml - Custom color schemes
Set in config: skin: <name>
Plugins
Location: ~/.config/k9s/plugins.yaml
Example Plugin
plugins:
stern:
shortCut: Shift+L
description: "Multi-pod logs with stern"
scopes:
- pods
command: stern
background: false
args:
- --context
- $CONTEXT
- --namespace
- $NAMESPACE
- $FILTER
Available variables: $NAMESPACE, $NAME, $CONTEXT, $CLUSTER, $USER, $COL-<column>
Workflow Examples
Debug Failing Deployment
:deploy→ find deploymentEnterto see pods- Select failing pod →
ddescribe (check events) lfor logspfor previous logs (if crashed)sto shell in for live debugging
Monitor Rollout
:deploy→ select deploymentEnterto see ReplicaSets- Watch old RS scale down, new RS scale up
- Check pod status in new RS
Quick Cluster Health
:pulsefor overview:node→ check node status:event→ recent cluster eventsShift+c/Shift+mto sort by resource usage
Investigate Memory Issues
:pod→Shift+m(sort by memory)- Identify high consumers
ddescribe for limits/requestsllogs for memory-related errors
Tips
- Speed: Learn
:po,:dp,:svcshortcuts - Favorites: Mark frequently-used namespaces with
u - Save often:
Ctrl+ssaves current view to/tmp/k9s-screens-<user>/ - Mouse: Enable in config if preferred
- Context switching:
:ctxto quickly switch clusters - Wide view:
Ctrl+wshows more columns (node, IP, etc.) - Xray:
:xray deployshows deployment→RS→pod tree
微信扫一扫