AgentSkillsCN

k9s-ui

K9s 终端 UI,专为 Kubernetes 集群管理而设计。适用于以交互方式导航集群、实时查看日志、通过终端 UI 管理资源,或当用户提到 K9s、终端 Kubernetes,或交互式集群管理时使用。涵盖键盘快捷键、导航操作、插件配置与个性化设置。

SKILL.md
--- frontmatter
name: k9s-ui
description: k9s terminal UI for Kubernetes cluster management. Use when navigating clusters interactively, viewing logs in real-time, managing resources through terminal UI, or when user mentions k9s, terminal kubernetes, or interactive cluster management. Covers keyboard shortcuts, navigation, plugins, and configuration.

k9s Terminal UI

k9s provides a terminal-based UI for Kubernetes cluster management with real-time updates and keyboard-driven navigation.

Launch Options

bash
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

CommandResource
:pod / :poPods
:deploy / :dpDeployments
:svcServices
:nsNamespaces
:node / :noNodes
:rsReplicaSets
:dsDaemonSets
:stsStatefulSets
:cmConfigMaps
:secret / :secSecrets
:pvcPersistentVolumeClaims
:pvPersistentVolumes
:ingIngresses
:cjCronJobs
:jobJobs
:hpaHorizontalPodAutoscalers
:epEndpoints
:saServiceAccounts
:ctxContexts
:event / :evEvents

Special Commands

CommandAction
:aliasesShow all resource aliases
:xray <resource>Tree view of resource dependencies
:pulseCluster health pulse view
:popeyeRun cluster linter (if installed)
:dir <path>Browse saved files
:q / :quitExit k9s

Global Keyboard Shortcuts

KeyAction
?Help / Show all shortcuts
EscBack / Cancel / Exit mode
Ctrl+aShow all resources in namespace
Ctrl+eToggle header
Ctrl+wToggle wide columns
Ctrl+sSave resource YAML to file
/Filter mode (regex search)
0-9Quick namespace switch (favorites)

Resource-Specific Actions

Pods

KeyAction
lView logs
pView previous container logs
sShell into container
aAttach to container
dDescribe
yView YAML
eEdit
Ctrl+dDelete
Ctrl+kKill (force delete)
fPort forward
Shift+fPort forward menu

Deployments

KeyAction
sScale replicas
rRestart (rollout restart)
dDescribe
yView YAML
eEdit
Ctrl+lRollback

General Resources

KeyAction
EnterSelect / View details
dDescribe
yView YAML
eEdit (opens $EDITOR)
Ctrl+dDelete (with confirmation)
Ctrl+kKill (no confirmation)

Sorting

KeySort By
Shift+cCPU
Shift+mMemory
Shift+sStatus
Shift+pNamespace
Shift+nName
Shift+oNode
Shift+iIP Address
Shift+aAge

Filtering & Search

code
/                    # 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/CommandAction
:nsList namespaces
uMark as favorite (adds +)
0-9Quick switch to favorite
EnterSwitch to namespace

Favorites appear in header for quick access.

Logs View

Within pod logs (l):

KeyAction
0Tail all containers
1-9Tail specific container
wToggle wrap
tToggle timestamps
sToggle auto-scroll
/Search in logs
Ctrl+sSave logs to file
mMark current position
Ctrl+bPage up
Ctrl+fPage down

Port Forwarding

After selecting a pod and pressing Shift+f:

  1. Select container/port
  2. Enter local port
  3. Port forward starts in background
  4. View active forwards: :pf

Configuration

Config Location

code
~/.config/k9s/config.yaml     # Main config (Linux)
~/Library/Application Support/k9s/config.yaml  # macOS

Key Settings

yaml
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:

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

yaml
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

  1. :deploy → find deployment
  2. Enter to see pods
  3. Select failing pod → d describe (check events)
  4. l for logs
  5. p for previous logs (if crashed)
  6. s to shell in for live debugging

Monitor Rollout

  1. :deploy → select deployment
  2. Enter to see ReplicaSets
  3. Watch old RS scale down, new RS scale up
  4. Check pod status in new RS

Quick Cluster Health

  1. :pulse for overview
  2. :node → check node status
  3. :event → recent cluster events
  4. Shift+c / Shift+m to sort by resource usage

Investigate Memory Issues

  1. :podShift+m (sort by memory)
  2. Identify high consumers
  3. d describe for limits/requests
  4. l logs for memory-related errors

Tips

  • Speed: Learn :po, :dp, :svc shortcuts
  • Favorites: Mark frequently-used namespaces with u
  • Save often: Ctrl+s saves current view to /tmp/k9s-screens-<user>/
  • Mouse: Enable in config if preferred
  • Context switching: :ctx to quickly switch clusters
  • Wide view: Ctrl+w shows more columns (node, IP, etc.)
  • Xray: :xray deploy shows deployment→RS→pod tree