5.3 KiB
5.3 KiB
Kubernetes 集群快速修复指南
更新时间: 2026-01-04 集群版本: Kubernetes v1.33.5 (OrbStack)
🚨 紧急问题快速修复
问题 1: Grafana 组件无法启动 (Loki, Tempo)
症状: ImagePullBackOff 错误,Docker Hub 拉取超时
1分钟快速修复:
cd /Users/brunogao/work/codes/tools/macos/k8s
./fix-cluster-issues.sh fix-grafana
手动修复:
./cache-image.sh grafana/loki:latest grafana/tempo:latest
kubectl delete pod -n infra loki-0 tempo-0
问题 2: 大量镜像拉取超时
症状: 多个 Pod 处于 ImagePullBackOff 状态
10分钟批量修复:
cd /Users/brunogao/work/codes/tools/macos/k8s
./fix-cluster-issues.sh cache-p1
一键全自动修复 (推荐):
./fix-cluster-issues.sh auto
问题 3: dev 命名空间 Pod 无法启动
症状: harbor.omniverseai.net/ljwx/xxx:dev 镜像不存在
解决方案 A: 检查 CI/CD 是否构建了镜像
# 检查 Harbor 仓库
curl -u admin:admin123 http://192.168.1.83:8080/api/v2.0/projects/ljwx/repositories
解决方案 B: 暂时删除失败的 Deployment
./fix-cluster-issues.sh clean-dev
📋 诊断工具
查看所有失败的 Pod
./fix-cluster-issues.sh diagnose
查看镜像拉取错误
./fix-cluster-issues.sh check-errors
手动检查命令
# 查看所有非正常 Pod
kubectl get pods --all-namespaces --field-selector=status.phase!=Running,status.phase!=Succeeded
# 查看镜像拉取事件
kubectl get events --all-namespaces --field-selector type=Warning | grep -i "image\|pull"
# 查看 Pod 详细状态
kubectl describe pod -n <namespace> <pod-name>
🛠️ 交互式修复工具
启动交互式菜单:
cd /Users/brunogao/work/codes/tools/macos/k8s
./fix-cluster-issues.sh
菜单选项:
- 🔥 修复 Grafana 组件
- 📦 批量缓存 P1 镜像
- 🧹 清理 dev 命名空间
- 📊 诊断失败的 Pod
- 🔍 检查镜像拉取错误
- ⚡ 全自动修复 (推荐)
- 📈 部署 Metrics Server
📁 生成的文件说明
| 文件 | 用途 |
|---|---|
K8S-CLUSTER-ANALYSIS-2026-01-04.md |
完整的集群分析和优化方案 |
images-to-cache-priority.txt |
镜像缓存优先级列表(详细版) |
images-to-cache-p1.txt |
P1 高优先级镜像列表(批量缓存用) |
fix-cluster-issues.sh |
一键修复脚本(交互式/命令行) |
⚡ 快捷命令清单
# 进入工作目录
cd /Users/brunogao/work/codes/tools/macos/k8s
# === 镜像缓存 ===
# 缓存单个镜像
./cache-image.sh <image:tag>
# 批量缓存镜像
./cache-image.sh -f images-to-cache-p1.txt
# 更新 Deployment 并缓存镜像
./cache-image.sh --update-deployment <namespace>/<deployment>
# === Pod 管理 ===
# 查看所有 Pod 状态
kubectl get pods --all-namespaces -o wide
# 重启 Pod
kubectl delete pod -n <namespace> <pod-name>
# 查看 Pod 日志
kubectl logs -n <namespace> <pod-name> --tail=100
# 查看 Pod 详细信息
kubectl describe pod -n <namespace> <pod-name>
# === 镜像管理 ===
# 查看所有使用的镜像
kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | sort -u
# 查看镜像拉取错误
kubectl get events --all-namespaces --field-selector type=Warning | grep -i "image\|pull"
# === Deployment 管理 ===
# 查看所有 Deployment
kubectl get deployments --all-namespaces
# 更新 Deployment 镜像
kubectl set image deployment/<name> <container>=<new-image> -n <namespace>
# 回滚 Deployment
kubectl rollout undo deployment/<name> -n <namespace>
# === 节点和资源 ===
# 查看节点状态
kubectl get nodes -o wide
# 查看节点资源使用 (需要 Metrics Server)
kubectl top nodes
# 查看 Pod 资源使用
kubectl top pods --all-namespaces
📊 当前集群问题统计
镜像拉取失败 (P0)
infra/loki-0: grafana/loki:latestinfra/tempo-0: grafana/tempo:latestdev/backend: harbor.omniverseai.net/ljwx/backend-template:devdev/frontend: harbor.omniverseai.net/ljwx/frontend-dashboard:devdev/quality-dashboard: harbor.omniverseai.net/ljwx/quality-dashboard:dev
应用崩溃 (P1)
external-secrets-system/external-secrets: 重启 764 次observability/prometheus-adapter: 重启 100 次ljwx-project/pcc-backend: 重启 1901 次ljwx-project/pcc-frontend: 重启 1907 次ljwx-stock/claude-stock-backend: 重启 2122 次
高重启次数 (P2)
cert-manager/cert-manager-webhook-dnspod: 重启 2490 次stock/stock-backend: 重启 1154, 1194 次infra/ingress-nginx-defaultbackend: 重启 220 次
🎯 推荐执行顺序
第一步: 紧急修复 (5 分钟)
./fix-cluster-issues.sh auto
第二步: 验证修复效果 (2 分钟)
./fix-cluster-issues.sh diagnose
第三步: 处理 dev 命名空间 (可选)
./fix-cluster-issues.sh clean-dev
第四步: 部署 Metrics Server (可选)
./fix-cluster-issues.sh metrics
📞 需要帮助?
查看完整分析报告:
cat K8S-CLUSTER-ANALYSIS-2026-01-04.md
查看镜像缓存优先级:
cat images-to-cache-priority.txt
祝您修复顺利! 🎉