Communitygithub.com

G1Joshi/Agent-Skills

專業 K9s CLI 輔助技能,涵蓋終端機 Kubernetes 叢集導覽、即時日誌串流、連接埠轉發與 Pod 除錯。適用於快速管理與疑難排解 Kubernetes 叢集。

Agent-Skills 是什麼?

此技能專為需要在終端機環境中高效管理 Kubernetes 叢集的開發者與平台工程師設計。它深度整合 K9s 終端機 UI,提供比傳統 kubectl 更快速、更直覺的互動式操作,包含即時 Pod 日誌串流、資源監控、連接埠轉發及自定義外掛擴充。技能支援透過 plugins.yaml 設定快捷鍵,將重複性的 kubectl 指令(如檢查部署歷程或啟動除錯容器)一鍵化。此外,它強調生產環境安全,提供 `--readonly` 唯讀模式與適當的 `--refresh` 間隔設定建議。無論是在開發、測試或生產叢集中進行故障排除、資源巡覽或日誌分析,此技能都能顯著提升工作效率。主要支援平台為 K9s CLI,並與標準 kubectl 設定相容。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/tools/k9s

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

K9s

K9s 是 Kubernetes 的終端機 UI(TUI)。它比點擊網頁儀表板更快,也比原始的 kubectl 更容易探索。

使用時機

  • 基於終端機的 Kubernetes 叢集管理:快速、互動式的 curses UI,用於導覽 Pod、Service 與 Deployment。
  • 即時日誌串流與資源監控:追蹤多個 Pod 的日誌、按 CPU/記憶體排序,以及連接埠轉發。
  • 自訂 K9s 外掛與別名:透過自訂 Shell 指令(例如執行 stern、cert-manager status)擴充 CLI。
  • 唯讀檢查與疑難排解:以唯讀模式安全地除錯生產叢集。

快速開始

# 以現有 kubeconfig 啟動 k9s
k9s

# k9s 中的導覽快捷鍵:
# :pods      - 檢視所有命名空間中的 Pod
# :deploy    - 檢視 Deployment
# :svc       - 檢視 Service
# /<term>    - 在目前檢視中過濾項目
# l          - 串流選取 Pod 的日誌
# s          - 在選取容器內開啟 Shell (exec)

核心概念

#自訂外掛設定(plugins.yaml)

新增自訂鍵盤指令以快速除錯:

# ~/.config/k9s/plugins.yaml
plugin:
  # 在 Deployment 上按 'Shift-D' 來檢視詳細的更新歷程
  rollout-history:
    shortCut: Shift-D
    confirm: false
    description: "更新歷程"
    scopes:
      - deployments
    command: kubectl
    background: false
    args:
      - rollout
      - history
      - deployment/$NAME
      - -n
      - $NAMESPACE

  # 在 Pod 上按 'Shift-F' 來啟動互動式除錯容器
  debug-pod:
    shortCut: Shift-F
    confirm: true
    description: "除錯 Pod"
    scopes:
      - pods
    command: kubectl
    background: false
    args:
      - debug
      - -it
      - $NAME
      - --image=nicolaka/netshoot
      - -n
      - $NAMESPACE

#重要導覽與鍵盤快捷鍵

加速叢集管理:

  • :pod:跳至所有命名空間的 Pod 檢視。
  • :svc、:deploy、:ing:跳至 Service、Deployment 與 Ingress 檢視。
  • /:依名稱或狀態搜尋與過濾資源。
  • l:追蹤選取 Pod 或容器的日誌。
  • s:在選取容器內開啟互動式 Shell(sh / bash)。
  • Shift-F:將本機連接埠轉發至選取 Pod 的服務連接埠。
  • y:檢視選取資源的完整 YAML 清單。

#以自訂選項啟動 K9s

以安全模式啟動 K9s:

# 以唯讀模式啟動,防止在生產環境中意外刪除 Pod
k9s --readonly --namespace production

# 指定自訂 context 與重新整理頻率
k9s --context prod-eks-cluster --refresh 2

常見模式

#自訂 K9s 快捷鍵與外掛 問題:在不同命名空間中頻繁執行自訂 kubectl 指令。 解決方案:在 ~/.config/k9s/plugin.yaml 中定義自訂外掛。

# ~/.config/k9s/plugin.yaml
plugin:
  raw-logs:
    shortCut: Shift-L
    description: "追蹤未截斷的日誌"
    scopes:
      - pods
    command: kubectl
    background: false
    args:
      - logs
      - -f
      - $NAME
      - -n
      - $NAMESPACE
      - --context
      - $CONTEXT

最佳實踐(2026)

  • 務必在連接到生產環境時使用 k9s --readonly,以防止意外刪除。
  • 務必在 ~/.config/k9s/plugins.yaml 中設定自訂外掛,以處理重複性的 kubectl 指令。
  • 務必使用連接埠轉發快捷鍵(Shift-F),而不是輸入冗長的 kubectl port-forward 指令。
  • 務必使用 <all> 命名空間或特定命名空間來過濾檢視,以減少 API 伺服器的查詢負載。
  • 切勿保持數十個活躍的連接埠轉發;請在 :portforwards 檢視中管理並終止它們。
  • 切勿在沒有設定適當的 --refresh 間隔的情況下,對大型企業叢集執行 K9s。
  • 切勿在未確認備份的情況下,透過 K9s 刪除持續性磁碟區聲明(PVC)。

疑難排解

錯誤原因解決方案
Boom!! K9s 無法連接到叢集目前的 kubeconfig 環境無效,或叢集端點無法連線。驗證連線:kubectl cluster-info,並使用 kubectl config use-context 切換環境。
在 k9s 中 Pod 日誌串流失敗Pod 容器崩潰,或使用者缺乏 RBAC pods/log 權限。檢查容器狀態,並驗證叢集角色權限。
終端機顯示畫面損毀/出現異常不相容的終端機 terminfo,或終端機視窗太小。執行 export TERM=xterm-256color,並將終端機視窗最大化。

參考資料

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

G1Joshi/Agent-Skills

Expert Dask distributed computing assistance covering Dask DataFrames, Arrays, Futures, and cluster scaling. Use when analyzing datasets too large for pandas on a single machine or multi-node cluster.

G1Joshi/Agent-Skills

Expert dbt (data build tool) assistance covering SQL modeling, Jinja macros, tests, documentation, and semantic layer. Use when building analytics engineering pipelines on BigQuery, Snowflake, or PostgreSQL.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert SWC assistance covering high-performance Rust-based JavaScript/TypeScript compilation, .swcrc configuration, Jest testing via @swc/jest, and minification. Use when replacing Babel with SWC for faster builds, accelerating test execution, or compiling modern ECMAScript features.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert Zsh assistance covering shell customization, Oh My Zsh plugins, Zinit plugin manager, prompt engineering (Starship/Powerlevel10k), and shell scripting. Use when configuring .zshrc, writing Zsh automation scripts, optimizing shell startup time, or configuring tab-completion.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

相關技能