主题
故障排查
通用排查思路
1. 确认节点状态 kubectl get node
2. 查看 Pod 状态 kubectl get pod -A
3. 查看异常 Pod 日志 kubectl logs <pod> -n <ns>
4. 查看 Pod 事件 kubectl describe pod <pod> -n <ns>
5. 检查中间件状态 kubectl get pod -n yidun-infra
6. 检查磁盘/内存 kubectl top node; df -h常用快捷命令
bash
# 查看所有非 Running/Completed 的 Pod
kubectl get pod -A | grep -v -E "Running|Completed"
# 查看近期错误事件
kubectl get events -A --sort-by='.lastTimestamp' \
| grep -i -E "error|failed|backoff" | tail -30
# 查看某命名空间所有日志(多 Pod)
kubectl logs -l app=antispam -n yidun --tail=100
# 查看 Pod 重启次数最多的 Pod
kubectl get pod -A --sort-by='.status.containerStatuses[0].restartCount'部署阶段问题
K3s 安装失败
症状:步骤 5 卡住或报错
bash
# 查看 ansible 执行详情
cd k3s_ansible
ansible-playbook -i inventory/dev/host.ini cluster.yml -b -vvv 2>&1 | tail -50
# 在目标节点检查 k3s 安装状态
systemctl status k3s
journalctl -u k3s -n 100
# 常见原因:flannel_iface 配置错误(网卡名不存在)
ip link show | grep -v lo
# 找到正确的网卡名后更新 auto-docker.conf 中的 k3s_flannel_iface解决:修正配置后,删除状态文件重新执行:
bash
rm -f .deploy_state/step_5_k3s.done
FORCE_STEP=5 bash autoinstall-docker.sh镜像导入失败
症状:步骤 4 报错或 Pod ImagePullBackOff
bash
# 检查 registry 服务
docker ps | grep registry
curl http://private-registry.yidun.internal/v2/_catalog
# 检查 /etc/hosts
grep "private-registry" /etc/hosts
# 手动导入单个镜像
docker load -i <image.tar>
docker push private-registry.yidun.internal/<image>:<tag>中间件 Pod Pending
症状:步骤 6 中 Pod 长时间 Pending
bash
# 查看调度失败原因
kubectl describe pod <pod-name> -n yidun-infra
# 常见原因 1:节点标签未打
kubectl get node --show-labels | grep kafka
# 修复
kubectl label node <node-name> kafka=true
# 常见原因 2:资源不足
kubectl describe node <node-name> | grep -A 5 "Allocatable"
# 常见原因 3:PVC 无法绑定
kubectl get pvc -n yidun-infra
kubectl describe pvc <pvc-name> -n yidun-infra数据初始化失败
症状:步骤 7 MySQL 导入报错
bash
# 测试数据库连接
mysql -h 127.0.0.1 -P <nodeport> -u admin -p'eHSkDv7c77*j' -e "SELECT 1"
# 查看 MySQL Pod 状态
kubectl get pod -n tidb
# 手动重试导入
FORCE_STEP=7 bash autoinstall-docker.sh运行时问题
Pod 频繁重启(CrashLoopBackOff)
bash
# 查看当前日志
kubectl logs <pod-name> -n yidun
# 查看上一次崩溃的日志
kubectl logs <pod-name> -n yidun --previous
# 常见原因
# 1. 中间件未就绪(Kafka/ZK/MySQL 连接失败)
# 2. 配置错误(数据库地址/密码错误)
# 3. 内存 OOM(limits 太小)
kubectl describe pod <pod-name> -n yidun | grep -A 5 "OOM\|Killed\|Limits"OOMKilled
bash
# 查看 Pod 被 OOM Kill 的历史
kubectl get pod -n yidun -o json | jq '.items[] |
select(.status.containerStatuses[].lastState.terminated.reason=="OOMKilled") |
.metadata.name'
# 临时增大 memory limit
kubectl edit deployment <deployment> -n yidun
# 修改 resources.limits.memory
# 或通过 helm upgrade 修改 values
helm upgrade <release> . --set resources.limits.memory=2Gi -n yidun节点 NotReady
bash
# 查看节点状态详情
kubectl describe node <node-name>
# 检查 K3s 状态
ssh root@<node-ip> "systemctl status k3s"
ssh root@<node-ip> "journalctl -u k3s -n 50"
# 网络问题排查
kubectl exec -n kube-system -it <coredns-pod> -- nslookup kubernetes
# 重启 K3s(谨慎!会短暂中断该节点上的所有服务)
ssh root@<node-ip> "systemctl restart k3s"Kafka 消息积压
bash
# 查看所有 consumer group 的 lag
kubectl exec -it kafka-yidun-0 -n yidun-infra -- \
kafka-consumer-groups.sh --bootstrap-server localhost:9092 \
--describe --all-groups | grep -v "0$"
# 查看 topic 详情
kubectl exec -it kafka-yidun-0 -n yidun-infra -- \
kafka-topics.sh --bootstrap-server localhost:9092 \
--describe --topic <topic-name>ES 集群 RED
bash
# 查看未分配的分片
curl http://localhost:30092/_cluster/allocation/explain?pretty
# 强制重新分配
curl -X POST "http://localhost:30092/_cluster/reroute?retry_failed=true"
# 单节点时关闭 replica
curl -X PUT "http://localhost:30092/_settings" \
-H "Content-Type: application/json" \
-d '{"index": {"number_of_replicas": 0}}'网络问题
Pod 间无法通信
bash
# 检查网络连通性
cd k8s-apps/01-devops
bash check-network.sh
# 查看 CNI 状态(Flannel)
kubectl get pod -n kube-system | grep flannel
# 手动测试 Pod 间通信
kubectl exec -it <pod-a> -n yidun -- \
curl http://antispam-business.yidun.svc:8080/healthDNS 解析失败
bash
# 测试 CoreDNS
kubectl exec -it <any-pod> -n yidun -- \
nslookup kafka-yidun-headless.yidun-infra.svc.cluster.local
# 查看 CoreDNS 日志
kubectl logs -n kube-system -l k8s-app=kube-dns
# 检查 CoreDNS 配置
kubectl get configmap coredns -n kube-system -o yaml存储问题
PVC 一直 Pending
bash
# 查看 StorageClass
kubectl get storageclass
# 检查 local-path provisioner
kubectl get pod -n kube-system | grep local-path
# 查看 provisioner 日志
kubectl logs -n kube-system -l app=local-path-provisioner磁盘空间不足
bash
# 查看各节点磁盘使用
kubectl get node -o json | jq '.items[] |
{name: .metadata.name,
disk: .status.allocatable["ephemeral-storage"]}'
# 清理 K3s 未使用镜像
k3s crictl rmi --prune
# 清理 Docker 未使用资源
docker system prune -a日志收集
问题无法自行解决时,收集以下信息给售后支持:
bash
# 1. 集群基本状态
kubectl get node -o wide > cluster-status.txt
kubectl get pod -A -o wide >> cluster-status.txt
# 2. 异常 Pod 日志
kubectl logs <pod-name> -n <namespace> --previous > pod-logs.txt
# 3. K3s 系统日志
journalctl -u k3s --since "1 hour ago" > k3s-logs.txt
# 4. 事件列表
kubectl get events -A --sort-by='.lastTimestamp' > events.txt
# 打包
tar czf support-$(date +%Y%m%d%H%M).tar.gz \
cluster-status.txt pod-logs.txt k3s-logs.txt events.txt