with one click
kubernetes
Kubernetes 常用操作、Pod 调试、资源排查、HPA 自动扩缩容、ConfigMap/Secret 管理
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Kubernetes 常用操作、Pod 调试、资源排查、HPA 自动扩缩容、ConfigMap/Secret 管理
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
生成或审计模块的 SPEC.md。使用场景:用户要求"给 XX 模块写 spec"、"审计所有 spec"、"检查 spec 是否过期"。
Automates SailFish release workflow: fix build/type errors, update CHANGELOG (EN + CN), run npm version with pre/post hooks. Use when the user asks to release, 发版, 发布, bump version, or update changelog.
后端代码修改后,通过 CLI 测试验证功能正确性。使用场景:修改了 electron/services/ 下的代码需要测试、准备提交代码前跑回归、用户要求"跑测试"/"验证一下"。
完成新功能开发或较大修改后,使用本机 Claude CLI 进行代码审查。
使用 ts-morph 静态分析工具查询代码结构(类层次、方法签名、引用、依赖等),替代手动读源码。使用场景:需要了解类的方法/属性、继承链、符号引用、文件结构、依赖关系时。
When committing or staging changes, only include files related to the current task or conversation; do not stage or commit unrelated modifications. Use when the user asks to commit, stage, 提交, or when preparing to run git add/commit.
| name | Kubernetes 运维指南 |
| description | Kubernetes 常用操作、Pod 调试、资源排查、HPA 自动扩缩容、ConfigMap/Secret 管理 |
| version | 1.0.0 |
kubectl cluster-info
kubectl get nodes -o wide
kubectl top nodes # 需要 metrics-server
kubectl api-resources # 所有资源类型
# 查看
kubectl get pods -n <ns> -o wide
kubectl get deploy,sts,ds -n <ns>
kubectl describe pod <pod> -n <ns>
# 扩缩容
kubectl scale deploy <name> --replicas=3 -n <ns>
# 滚动更新
kubectl set image deploy/<name> <container>=<image>:<tag> -n <ns>
kubectl rollout status deploy/<name> -n <ns>
kubectl rollout history deploy/<name> -n <ns>
# 回滚
kubectl rollout undo deploy/<name> -n <ns>
kubectl rollout undo deploy/<name> --to-revision=2 -n <ns>
# 查看日志
kubectl logs <pod> -n <ns> --tail=100 -f
kubectl logs <pod> -c <container> -n <ns> # 多容器 Pod
kubectl logs <pod> -n <ns> --previous # 上一个崩溃的容器
# 进入容器
kubectl exec -it <pod> -n <ns> -- /bin/bash
kubectl exec -it <pod> -c <container> -n <ns> -- /bin/sh
# 临时调试容器(K8s 1.23+)
kubectl debug -it <pod> -n <ns> --image=busybox --target=<container>
# 端口转发
kubectl port-forward svc/<service> 8080:80 -n <ns>
| 状态 | 排查思路 |
|---|---|
| Pending | describe pod → 检查资源不足、节点亲和性、PVC 未绑定 |
| CrashLoopBackOff | logs --previous → 检查启动命令、配置、依赖服务 |
| ImagePullBackOff | 检查镜像名/tag、镜像仓库认证 (imagePullSecrets)、网络 |
| OOMKilled | describe pod → 增大 resources.limits.memory |
| Evicted | 节点磁盘/内存压力 → kubectl describe node 检查 Conditions |
| Terminating 卡住 | kubectl delete pod <pod> --grace-period=0 --force |
# 从文件创建
kubectl create configmap app-config --from-file=config.yaml -n <ns>
kubectl create secret generic db-creds --from-literal=password=xxx -n <ns>
# 查看
kubectl get configmap app-config -n <ns> -o yaml
kubectl get secret db-creds -n <ns> -o jsonpath='{.data.password}' | base64 -d
# 热更新(挂载为文件的 ConfigMap 会自动更新,环境变量不会)
kubectl edit configmap app-config -n <ns>
# 创建 HPA(需要 metrics-server)
kubectl autoscale deploy <name> --min=2 --max=10 --cpu-percent=70 -n <ns>
# 查看
kubectl get hpa -n <ns>
kubectl describe hpa <name> -n <ns>
# 1. 事件排查
kubectl get events -n <ns> --sort-by='.lastTimestamp' | tail -20
# 2. 资源使用
kubectl top pods -n <ns> --sort-by=memory
kubectl top nodes
# 3. 网络连通性
kubectl run tmp-debug --rm -it --image=busybox -- /bin/sh
# 在 Pod 内: nslookup <service>.<ns>.svc.cluster.local
# 4. 查看 Service 端点
kubectl get endpoints <service> -n <ns>
# 5. DNS 排查
kubectl run dns-test --rm -it --image=busybox -- nslookup kubernetes.default
resources.requests 和 resources.limits