关于 k8s
k8s 是用于访问和排查 Kubernetes 集群的操作技能,面向日常集群维护人员。它提供 kubectl 与 Flux 的常用检查方式,并说明 Flux 状态及陌生服务文档的调研方法。
主要功能
- 01dev、integration 与 live 集群访问指引
- 02kubectl 资源、日志和事件检查
- 03Flux 状态检查与协调操作
- 04Flux 状态含义及处理建议
- 05陌生服务文档调研流程
适用场景
- 01检查 Pod 状态、日志和资源用量
- 02诊断 Flux 管理的部署未就绪问题
- 03查找陌生服务的故障模式与健康指标
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ionfury/ homelab --skill k8s安装后在 Claude Code 中输入/k8s确认已加载。
附带文件services.mdtests.yaml
详细介绍
访问集群
可用集群为 dev、integration 和 live。请使用对应的 kube context 进行访问。
常用 kubectl 模式
| 命令 | 用途 |
|---|---|
kubectl get pods -n <ns> | 列出某命名空间中的 Pod |
kubectl get pods -A | 列出所有命名空间中的 Pod |
kubectl describe pod <pod> -n <ns> | 查看 Pod 详细信息及事件 |
kubectl logs <pod> -n <ns> --tail=100 | 查看 Pod 的近期日志 |
kubectl logs <pod> -n <ns> --previous | 查看上一个容器实例的日志 |
kubectl get events -n <ns> --sort-by='.lastTimestamp' | 近期事件时间线 |
kubectl top pods -n <ns> | 每个 Pod 的 CPU/内存使用情况 |
kubectl top nodes | 每个节点的 CPU/内存使用情况 |
kubectl get ns <ns> --show-labels | 命名空间标签(网络策略配置文件) |
kubectl explain <resource> | 某资源类型的 API schema 参考 |
Flux GitOps 命令
# Check status
flux --context <cluster> get all
flux --context <cluster> get kustomizations
flux --context <cluster> get helmreleases -A
# Trigger reconciliation
flux --context <cluster> reconcile source git flux-system
flux --context <cluster> reconcile kustomization <name>
flux --context <cluster> reconcile helmrelease <name> -n <namespace>
Flux 状态解读
| 状态 | 含义 | 操作 |
|---|---|---|
Ready: True | 已协调且健康 | 无 |
Ready: False | 协调失败 | 检查 message/reason |
Stalled: True | 反复失败后停止重试 | 挂起/恢复以重置(见 sre skill) |
Suspended: True | 有意暂停 | 恢复:flux resume <type> <name> |
Reconciling | 正在应用中 | 等待完成 |
研究不熟悉的服务
在调查未知服务时,启动一个 haiku agent 来研究文档:
Task tool:
- subagent_type: "general-purpose"
- model: "haiku"
- prompt: "Research [service] troubleshooting docs. Focus on:
1. Common failure modes
2. Health indicators
3. Configuration gotchas
Start with: [docs-url]"
Chart URL 到文档的映射:
| Chart 来源 | 文档 |
|---|---|
charts.jetstack.io | cert-manager.io/docs |
charts.longhorn.io | longhorn.io/docs |
grafana.github.io | grafana.com/docs |
prometheus-community.github.io | prometheus.io/docs |
常见混淆
BAD:使用 helm list 检查 Helm release 状态
GOOD:使用 kubectl get helmrelease -A —— Flux 通过 CRD 管理 release,而非 Helm CLI
评论
支持 Markdown