← 返回 Skills 市场
41
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install kubectl-skill
功能描述
Provides detailed kubectl command references for managing Kubernetes resources, cluster info, logs, debugging, context switching, and advanced operations.
使用说明 (SKILL.md)
kubectl
Kubernetes 命令行工具 (kubectl),用于与 Kubernetes 集群进行交互和管理资源。
何时使用
- 管理 Kubernetes 资源(Pod、Deployment、Service 等)
- 查看集群状态和日志
- 调试应用程序和容器
- 部署应用到集群
- 配置集群访问和上下文切换
- 执行容器内的命令
- 端口转发到 Pod
基本语法
kubectl [command] [TYPE] [NAME] [flags]
- command: 操作,如
create、get、describe、delete、apply - TYPE: 资源类型,支持单数/复数/缩写(如
pod/pods/po) - NAME: 资源名称,省略则显示所有资源
- flags: 可选参数
常用命令
资源查询
# 查看所有 Pod
kubectl get pods
# 查看所有 Pod(含节点信息)
kubectl get pods -o wide
# 查看特定 Pod 详情
kubectl describe pod \x3Cpod-name>
# 查看所有 Deployment
kubectl get deployments
# 查看所有 Service
kubectl get services
# 查看节点状态
kubectl get nodes
# 查看所有资源
kubectl get all
# 按标签筛选
kubectl get pods -l app=myapp
# 持续监视资源变化
kubectl get pods --watch
创建与更新资源
# 从文件创建资源
kubectl apply -f manifest.yaml
# 从目录创建资源
kubectl apply -f ./manifests/
# 从标准输入创建
kubectl apply -f -
# 创建 Deployment
kubectl create deployment \x3Cname> --image=\x3Cimage>
# 暴露 Service
kubectl expose deployment \x3Cname> --port=80 --type=LoadBalancer
# 滚动更新镜像
kubectl set image deployment/\x3Cname> \x3Ccontainer>=\x3Cnew-image>
# 水平扩展
kubectl scale deployment/\x3Cname> --replicas=5
删除资源
# 从文件删除
kubectl delete -f manifest.yaml
# 按名称删除 Pod
kubectl delete pod \x3Cpod-name>
# 按标签删除
kubectl delete pods -l app=myapp
# 删除所有 Pod
kubectl delete pods --all
日志与调试
# 查看 Pod 日志
kubectl logs \x3Cpod-name>
# 实时跟踪日志(类似 tail -f)
kubectl logs -f \x3Cpod-name>
# 查看指定容器日志
kubectl logs \x3Cpod-name> -c \x3Ccontainer-name>
# 查看之前容器的日志
kubectl logs \x3Cpod-name> --previous
# 在 Pod 中执行命令
kubectl exec \x3Cpod-name> -- \x3Ccommand>
# 进入 Pod 交互式 Shell
kubectl exec -it \x3Cpod-name> -- /bin/sh
# 进入指定容器的交互式 Shell
kubectl exec -it \x3Cpod-name> -c \x3Ccontainer> -- /bin/bash
# 端口转发
kubectl port-forward \x3Cpod-name> 8080:80
# 复制文件到/从容器
kubectl cp \x3Cpod-name>:/path/to/file ./local-file
kubectl cp ./local-file \x3Cpod-name>:/path/to/file
集群管理
# 查看当前上下文
kubectl config current-context
# 查看所有上下文
kubectl config get-contexts
# 切换上下文
kubectl config use-context \x3Ccontext-name>
# 设置当前上下文的默认命名空间
kubectl config set-context --current --namespace=\x3Cnamespace>
# 查看集群信息
kubectl cluster-info
# 查看 API 资源列表
kubectl api-resources
# 查看 API 版本
kubectl api-versions
高级操作
# 编辑资源(交互式)
kubectl edit deployment/\x3Cname>
# 打标签
kubectl label pods \x3Cpod-name> env=production
# 添加注解
kubectl annotate pods \x3Cpod-name> description="test"
# 查看资源差异
kubectl diff -f manifest.yaml
# 滚动更新管理
kubectl rollout status deployment/\x3Cname>
kubectl rollout history deployment/\x3Cname>
kubectl rollout undo deployment/\x3Cname>
# 排空节点(维护前)
kubectl drain \x3Cnode-name> --ignore-daemonsets
# 标记节点不可调度
kubectl cordon \x3Cnode-name>
# 标记节点可调度
kubectl uncordon \x3Cnode-name>
# 查看资源使用情况
kubectl top pods
kubectl top nodes
资源类型缩写
| 完整名称 | 缩写 |
|---|---|
| pods | po |
| services | svc |
| deployments | deploy |
| replicasets | rs |
| statefulsets | sts |
| daemonsets | ds |
| configmaps | cm |
| secrets | |
| nodes | no |
| namespaces | ns |
| persistentvolumeclaims | pvc |
| persistentvolumes | pv |
| ingresses | ing |
| jobs | |
| cronjobs | cj |
| serviceaccounts | sa |
| roles | |
| rolebindings | |
| clusterroles | |
| clusterrolebindings | |
| horizontalpodautoscalers | hpa |
输出格式
# JSON 格式
kubectl get pod \x3Cname> -o json
# YAML 格式
kubectl get pod \x3Cname> -o yaml
# 仅输出资源名称
kubectl get pods -o name
# 自定义列
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase
# JSONPath 输出
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
# 宽格式(含额外信息)
kubectl get pods -o wide
命名空间操作
# 指定命名空间
kubectl get pods -n \x3Cnamespace>
# 查看所有命名空间的资源
kubectl get pods --all-namespaces
kubectl get pods -A
# 创建命名空间
kubectl create namespace \x3Cname>
常用快捷命令
# 快速查看 Pod 状态
kubectl get pods --all-namespaces
# 快速查看所有事件
kubectl get events --sort-by='.lastTimestamp'
# 删除所有 Evicted Pod
kubectl get pods --all-namespaces --field-selector=status.phase=Failed | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs -L1 kubectl delete pod
# 强制删除 Terminating 的 Pod
kubectl delete pod \x3Cpod-name> --force --grace-period=0
配置说明
- 默认配置文件位于
$HOME/.kube/config - 可通过
KUBECONFIG环境变量指定其他配置文件 - 可通过
--kubeconfig参数指定配置文件
注意事项
- 命令行参数会覆盖默认值和环境变量
- 资源类型不区分大小写
- 名称区分大小写
- 在 Pod 内运行时,kubectl 会自动检测并使用 ServiceAccount 认证
- 使用
--dry-run=client或--dry-run=server可以预览操作效果而不实际执行
参考文档目录
本技能目录下的完整参考文档结构如下,可根据具体问题读取对应文件获取详细参数说明和示例:
概述与指南
_index.md- kubectl 命令行工具总览(语法、操作表、资源类型表、输出选项、常用示例、插件)conventions.md- kubectl 使用约定docker-cli-to-kubectl.md- Docker 用户迁移到 kubectl 的对照指南introduction.md- kubectl 简介jsonpath.md- JSONPath 语法支持quick-reference.md- 快速参考备忘单kubectl-cmds.md- kubectl 命令汇总kubectl.md- kubectl 概述kuberc.md- kuberc 偏好配置
主命令参考(generated)
generated/kubectl.md- kubectl 根命令参数说明generated/kubectl_alpha/- Alpha 阶段特性命令generated/kubectl_annotate/- 更新资源注解generated/kubectl_api-resources/- 列出 API 资源generated/kubectl_api-versions/- 列出 API 版本generated/kubectl_apply/- 应用配置(含 edit-last-applied、set-last-applied、view-last-applied)generated/kubectl_attach/- 挂接到运行中的容器generated/kubectl_auth/- 授权检查(含 can-i、reconcile、whoami)generated/kubectl_autoscale/- 自动扩缩generated/kubectl_certificate/- 证书管理(含 approve、deny)generated/kubectl_cluster-info/- 集群信息(含 dump)generated/kubectl_completion/- Shell 补全generated/kubectl_config/- kubeconfig 管理(含 current-context、delete-cluster、delete-context、delete-user、get-clusters、get-contexts、get-users、rename-context、set、set-cluster、set-context、set-credentials、unset、use-context、view)generated/kubectl_cordon/- 标记节点不可调度generated/kubectl_cp/- 文件复制generated/kubectl_create/- 创建资源(含 clusterrole、clusterrolebinding、configmap、cronjob、deployment、ingress、job、namespace、poddisruptionbudget、priorityclass、quota、role、rolebinding、secret、service、serviceaccount、token)generated/kubectl_debug/- 调试会话generated/kubectl_delete/- 删除资源generated/kubectl_describe/- 资源详情generated/kubectl_diff/- 配置差异对比generated/kubectl_drain/- 腾空节点generated/kubectl_edit/- 交互式编辑generated/kubectl_events/- 事件列表generated/kubectl_exec/- 容器内执行命令generated/kubectl_explain/- 资源文档说明generated/kubectl_expose/- 暴露服务generated/kubectl_get/- 查询资源generated/kubectl_kustomize/- Kustomize 构建generated/kubectl_label/- 更新标签generated/kubectl_logs/- 查看日志generated/kubectl_options/- 全局参数generated/kubectl_patch/- 更新资源字段generated/kubectl_plugin/- 插件管理(含 list)generated/kubectl_port-forward/- 端口转发generated/kubectl_proxy/- API 代理generated/kubectl_replace/- 替换资源generated/kubectl_rollout/- 发布管理(含 history、pause、restart、resume、status、undo)generated/kubectl_run/- 运行容器generated/kubectl_scale/- 手动扩缩generated/kubectl_set/- 设置对象属性(含 env、image、resources、selector、serviceaccount、subject)generated/kubectl_taint/- 节点污点管理generated/kubectl_top/- 资源使用监控(含 node、pod)generated/kubectl_uncordon/- 标记节点可调度generated/kubectl_version/- 版本信息generated/kubectl_wait/- 等待资源就绪
安全使用建议
This is a documentation-only kubectl reference (no code to execute), and its contents align with the stated purpose. Before installing or using it: 1) Note the source/homepage are unknown — prefer skills from trusted publishers. 2) Review the included files yourself; many examples show commands that read $HOME/.kube/config, KUBECONFIG, or extract secrets (jsonpath examples and `kubectl config view --raw`) — these will reveal credentials if you run them. 3) Do not run copy-paste commands that decode or output passwords/certificates unless you understand the consequences and are on a trusted machine. 4) If you plan to allow autonomous agent use, restrict that capability or monitor runs because an agent following these docs could suggest sensitive kubectl commands. If you want, I can scan the text for specific commands that would expose secrets and highlight them for you.
功能分析
Type: OpenClaw Skill
Name: kubectl-skill
Version: 1.0.0
The skill bundle is a comprehensive documentation and command reference for the Kubernetes command-line tool (kubectl). It provides the AI agent with a wide array of standard commands for managing clusters, including resource querying, creation, debugging (kubectl exec), and file transfer (kubectl cp), as seen in skill.md and the generated/ directory. The content is purely referential, aligning perfectly with its stated purpose, and contains no evidence of malicious instructions, data exfiltration, or prompt injection attempts.
能力标签
能力评估
Purpose & Capability
Name/description claim a kubectl CLI reference and the skill only contains documentation files and examples for kubectl commands. There are no unexpected binaries, install steps, or unrelated environment variables requested.
Instruction Scope
SKILL.md and the included docs provide typical kubectl usage and many examples. Some examples explicitly demonstrate reading $HOME/.kube/config, using KUBECONFIG/KUBERC, using `kubectl config view --raw`, and jsonpath snippets that extract passwords and certificate data. Those examples are relevant to a kubectl reference but also show exactly how to reveal cluster credentials/secrets — so treat the commands as sensitive and do not run them blindly.
Install Mechanism
Instruction-only skill with no install spec and no code files to write or execute. This is the lowest-risk install mechanism.
Credentials
The skill declares no required env vars or credentials. The documentation references common kubectl-related env/configuration (KUBECONFIG, KUBERC, $HOME/.kube/config) which is appropriate for the topic, but those references are to places that contain sensitive credentials — be aware the guidance shows how to read those values.
Persistence & Privilege
The skill is not always-enabled, is user-invocable, and does not request persistent privileges or modify other skills. Autonomous model invocation is allowed by default but not excessive here and not combined with other red flags.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install kubectl-skill - 安装完成后,直接呼叫该 Skill 的名称或使用
/kubectl-skill触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of kubectl-skill:
- Provides a comprehensive kubectl command reference and cheat sheet in Chinese.
- Includes usage guidance, syntax explanations, and practical command examples for resource management, logs, debugging, context switching, and more.
- Lists common resource abbreviations and output formatting options.
- Details advanced operations, configurations, and best practices.
- Outlines the directory and structure of the included reference documentation for easy lookup.
元数据
常见问题
k8s CLI command reference skill pack 是什么?
Provides detailed kubectl command references for managing Kubernetes resources, cluster info, logs, debugging, context switching, and advanced operations. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 41 次。
如何安装 k8s CLI command reference skill pack?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install kubectl-skill」即可一键安装,无需额外配置。
k8s CLI command reference skill pack 是免费的吗?
是的,k8s CLI command reference skill pack 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
k8s CLI command reference skill pack 支持哪些平台?
k8s CLI command reference skill pack 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 k8s CLI command reference skill pack?
由 XPDD(@xpdd)开发并维护,当前版本 v1.0.0。
推荐 Skills