在 CentOS + Kubernetes 环境中排查故障,一般遵循「从集群到节点,从节点到 Pod,从 Pod 到应用」的层级思路。下面给你一套实用排查流程和常用命令。
kubectl get componentstatuses
(新版本可能被 kubectl get --raw '/healthz' 替代)
kubectl get nodes -o wide
重点关注:
STATUS 是否为 ReadyROLESkubectl describe node <node-name>
重点看:
kubectl get pods -A
kubectl get pods -n <namespace>
常见异常状态:
Pending:调度问题CrashLoopBackOff:应用启动失败ImagePullBackOff:镜像拉取失败Terminating:删除卡住kubectl describe pod <pod-name> -n <namespace>
重点看:
kubectl logs <pod-name> -n <namespace>
kubectl logs <pod-name> -c <container-name> -n <namespace>
kubectl logs <pod-name> --previous -n <namespace>
kubectl exec -it <pod-name> -n <namespace> -- /bin/sh
kubectl describe pod <pod-name>
常见:
查看节点资源:
kubectl top node
kubectl top pod -A
kubectl get nodes -o json | jq '.items[].spec.taints'
kubectl get pods -n kube-system
常见 CNI:
kubectl exec -it <pod> -- ping <service-ip>
kubectl exec -it <pod> -- curl http://<service>:<port>
systemctl status firewalld
iptables -L -n
kubectl port-forward pod/<pod> 8080:80
journalctl -u kubelet -f
journalctl -u docker -f
journalctl -u containerd -f
systemctl status kubelet
systemctl restart kubelet
df -h
free -m
top
kubectl get pods -n kube-system
重点组件:
kube-apiserverkube-controller-managerkube-scheduleretcd查看 etcd:
kubectl exec -it etcd-master -n kube-system -- etcdctl endpoint health
kubectl get pod -o wide
kubectl describe pod
kubectl logs
kubectl exec
journalctl -u kubelet
如果你现在正好有具体故障,可以告诉我:
kubectl describe pod 的 Events我可以直接帮你定位到根因。