Communitygithub.com

G1Joshi/Agent-Skills

专业的 K9s CLI 辅助技能,涵盖终端 Kubernetes 集群导航、实时日志流式传输、端口转发和 Pod 调试。在需要快速管理和排查 Kubernetes 集群问题时使用。

Agent-Skills 是什么?

该技能为 AI 代理提供专业的 K9s 终端界面操作指导,专注于 Kubernetes 集群的高效管理和故障排查。它支持在终端中快速导航 Pod、服务、部署等资源,实现实时日志流式传输、资源监控、端口转发和自定义插件配置。技能涵盖了从基础启动命令(如 `k9s --readonly`)、核心导航快捷键(如 `:pods`、`/` 过滤、`l` 日志流、`s` 交互式 Shell)到高级自定义插件(如 `plugins.yaml` 中为部署添加回滚历史查看、为 Pod 添加调试容器启动)的完整工作流。通过优化快捷键和插件,该技能能大幅提升在 K9s 中的操作效率,减少对冗长 `kubectl` 命令的依赖,同时提供生产环境下的安全最佳实践(如只读模式、合理设置刷新间隔)和常见问题的故障排除方案,非常适合需要频繁与 Kubernetes 集群交互的开发者和运维人员。它适用于所有支持 K9s 的平台,如 Linux、macOS 和 Windows(通过 WSL)。

兼容平台~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 的终端用户界面 (TUI)。它比点击网页仪表盘更快,比原始 kubectl 更易发现。

使用时机

  • 终端 Kubernetes 集群管理:快速、交互式的 curses UI,用于导航 Pod、服务和部署。
  • 实时日志流式传输与资源监控:跟踪多个 Pod 的日志、按 CPU/内存排序以及端口转发。
  • 自定义 K9s 插件与别名:通过自定义 Shell 命令(例如运行 stern、cert-manager 状态)扩展 CLI。
  • 只读检查与故障排除:使用只读模式安全地调试生产集群。

快速开始

# 使用当前 kubeconfig 启动 k9s
k9s

# k9s 中的导航快捷键:
# :pods      - 跨命名空间查看所有 Pod
# :deploy    - 查看部署
# :svc       - 查看服务
# /<term>    - 在当前视图中过滤项目
# l          - 流式传输所选 Pod 的日志
# s          - 在所选容器中打开 Shell(exec)

核心概念

#自定义插件配置(plugins.yaml)

添加自定义键盘命令以加速调试:

# ~/.config/k9s/plugins.yaml
plugin:
  # 在部署上按 '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:跳转到服务、部署和 Ingress 视图。
  • /:按名称或状态搜索和过滤资源。
  • l:跟踪所选 Pod 或容器的日志。
  • s:在所选容器内打开交互式 Shell(sh / bash)。
  • Shift-F:将本地端口转发到所选 Pod 的服务端口。
  • y:查看所选资源的完整 YAML 清单。

#使用自定义选项启动 K9s

以安全模式启动 K9s:

# 以只读模式启动,防止在生产环境中意外删除 Pod
k9s --readonly --namespace production

# 指定自定义上下文和刷新频率
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 cannot connect to cluster活动 kubeconfig 上下文无效或集群端点不可达。验证连接:kubectl cluster-info 并使用 kubectl config use-context 切换上下文。
Pod logs failing to stream in k9sPod 容器崩溃或用户缺少 RBAC pods/log 权限。检查容器状态并验证集群角色权限。
Terminal display corrupted / artifacts不兼容的终端 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].

相关技能