Kubernetes Pod Pending 排查
现象
Pod 长时间停留在 Pending,没有被调度到任何 Node,业务实例无法启动。
kubectl get pods -A -o wide常见表现:
READY为0/1。STATUS为Pending。NODE为空。- Deployment 副本数一直不满足期望。
环境
- 集群:Kubernetes
- 对象:Pod / Deployment / StatefulSet
- 常用命令:
kubectl describe pod,kubectl get events
排查过程
- 查看 Pod 状态和所在 Namespace。
kubectl get pods -A -o wide- 查看 Pod 事件,重点看
FailedScheduling。
kubectl describe pod <pod-name> -n <namespace>- 查看集群近期事件。
kubectl get events -A --sort-by=.lastTimestamp- 查看节点资源和状态。
kubectl get nodes -o wide
kubectl describe node <node-name>
kubectl top nodes- 检查 Pod 的 requests、nodeSelector、affinity、tolerations、PVC。
kubectl get pod <pod-name> -n <namespace> -o yaml常见根因
| 根因 | 事件特征 | 排查方向 |
|---|---|---|
| CPU 或内存不足 | Insufficient cpu, Insufficient memory | 调整 requests 或扩容节点 |
| 节点污点不匹配 | taint / toleration | 检查 Node taints 和 Pod tolerations |
| nodeSelector 不匹配 | node(s) didn't match Pod's node affinity/selector | 检查标签和选择器 |
| 亲和性规则过严 | node affinity | 放宽 affinity 或补节点标签 |
| PVC 未绑定 | pod has unbound immediate PersistentVolumeClaims | 检查 PVC/PV/StorageClass |
| ResourceQuota 限制 | exceeded quota | 检查 Namespace 配额 |
解决方法
资源不足
kubectl describe pod <pod-name> -n <namespace>
kubectl top nodes处理方式:
- 降低不合理的
resources.requests。 - 扩容节点。
- 迁移或清理低优先级工作负载。
- 检查是否需要 Cluster Autoscaler。
污点和容忍不匹配
kubectl describe node <node-name> | grep -i taints
kubectl get pod <pod-name> -n <namespace> -o yaml处理方式:
- 给 Pod 增加合适的
tolerations。 - 或移除不必要的 Node taint。
PVC 未绑定
kubectl get pvc -n <namespace>
kubectl describe pvc <pvc-name> -n <namespace>
kubectl get storageclass处理方式:
- 修复 StorageClass。
- 创建匹配的 PV。
- 检查动态供给插件是否正常。
验证结果
kubectl get pod <pod-name> -n <namespace> -o wide
kubectl describe pod <pod-name> -n <namespace>确认点:
- Pod 从
Pending变为Running。 Events中不再出现新的FailedScheduling。- Deployment / StatefulSet 副本数恢复期望。
预防措施
- 给 Namespace 设置合理的 ResourceQuota 和 LimitRange。
- 定期检查节点可分配资源。
- Pod requests 按真实负载评估,避免随手写过大。
- 对 PVC 绑定失败和调度失败事件建立告警。
- 对节点标签、污点和亲和性规则做变更记录。