在 CentOS 上排 Kubernetes(k8s)故障,一般遵循**“从节点到集群、从底层到上层、从系统到应用”的思路。下面给你一套实用排障流程 + 常用命令**,适合生产环境。
kubectl get nodes
kubectl describe node <node-name>
重点看:
Ready / NotReadyConditionsEventstop
free -h
df -h
df -i # inode 满也很常见
systemctl status firewalld
getenforce
建议:
permissive 或关闭(生产按需)timedatectl
chronyc sources
systemctl status kubelet
journalctl -u kubelet -f
常见问题:
# docker
systemctl status docker
docker ps -a
# containerd
systemctl status containerd
ctr containers list
kubectl get pods -A
kubectl describe pod <pod> -n <ns>
常见状态:
Pending:调度 / 资源 / PVCCrashLoopBackOff:应用启动失败ImagePullBackOff:镜像拉取kubectl logs <pod> -n <ns>
kubectl logs <pod> -n <ns> -c <container>
kubectl logs <pod> -p -n <ns> # 上一次崩溃
kubectl exec -it <pod> -n <ns> -- sh
kubectl get svc -A
kubectl describe svc <svc>
检查:
kubectl exec -it <pod> -- nslookup kubernetes.default
kubectl get pods -n kube-system
journalctl -u kubelet
kubectl get cs
ETCDCTL_API=3 etcdctl endpoint health
kubeadm certs check-expiration
kubeadm certs renew all
kubectl describekubectl logsjournalctl| 现象 | 可能原因 |
|---|---|
| Node NotReady | kubelet挂 / 磁盘满 / 时间不同步 |
| Pod Pending | 资源不足 / 污点 / PVC |
| 镜像拉不下来 | 私有仓库 / 证书 / 代理 |
| 服务访问不通 | endpoint为空 / 网络插件 |
| 集群突然失控 | 证书过期 |
如果你愿意,可以把具体故障现象(比如某个 Pod 状态、报错日志)贴出来,我可以直接帮你定位。