DEBUG.WIKI
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
晚安云;香港 CN2 ¥15/月
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS

解决 Kubernetes 报错 pod has unbound immediate PersistentVolumeClaims 的排查指南

排查与解决 Kubernetes Pod 处于 Pending 状态并提示 pod has unbound immediate PersistentVolumeClaims 的完整方案。

问题现象

创建 StatefulSet 或带持久化存储的 Pod 后,Pod 长期保持在 Pending 状态,无法被调度到任何节点。通过 kubectl describe pod 发现事件:

Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  35s   default-scheduler  0/3 nodes are available: pod has unbound immediate PersistentVolumeClaims. preemption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling..

触发根因

  1. Pod 依赖的 PVC(PersistentVolumeClaim)处于 Pending 状态,尚未绑定到任何可用的 PV(PersistentVolume)。
  2. PVC 中指定的 storageClassName 不存在,或者该 StorageClass 的动态供应插件(CSI Provisioner)未能正常运行。
  3. 静态创建的 PV 容量、accessModes(如 ReadWriteOnce)与 PVC 要求的规格无法完全匹配。

解决步骤与操作命令

步骤一:查看关联 PVC 的详细状态与未绑定原因

运行命令检查集群命名空间下的 PVC:

kubectl get pvc -n production
kubectl describe pvc <claim_name> -n production

在 Events 区域查看具体报错,例如:

  • waiting for a volume to be created, either by external provisioner "nfs.csi.k8s.io" or manually created by system administrator
  • storageclass.storage.k8s.io "fast-ssd" not found

步骤二:检查集群 StorageClass 列表与默认存储类

查看集群已部署的存储类:

kubectl get sc

若未设置默认存储类,将可用的 StorageClass 标记为默认:

kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

步骤三:修改 PVC 匹配正确的存储类与访问模式

确保 PVC 中的声明与底层存储能力对齐:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-pvc
  namespace: production
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 10Gi

验证确认

重新应用配置:

kubectl get pvc -n production

PVC 状态转为 Bound,紧随其后 Pod 顺利被调度并在工作节点启动成功,状态变为 Running。