K8s 容器 Volume 挂载失败 / 挂载超时(MountVolume.SetUp 失败)排查
2026-08-11 09:37:39 # 存储

Pod 一直起不来,describe pod 里卡在 ContainerCreating,Events 里出现 MountVolume.SetUp failedfailed to mount——这是 K8s 存储最常见的”挂载类”故障。

典型报错形态

1
2
3
FailedMount: MountVolume.SetUp failed for volume "xxx" : failed to mount ...: timeout expired
FailedMount: MountVolume.SetUp failed: secret "xxx" not found
MountVolume.SetUp failed for volume "config" : configmap "yyy" not found

排查思路(按挂载对象分类)

1. 挂载 Secret / ConfigMap 失败

最常见也最”坑”:挂载对象不存在命名空间不对

1
2
kubectl get secret -n <ns>
kubectl get configmap -n <ns>

确认引用的名字、namespace 与挂载方一致;注意 defaultMode 导致的权限问题也会让挂载”看起来失败”。

2. 挂载远程存储(NFS / CephFS / RBD)超时

  • 网络不通:在计算节点 showmount -e <nfs-ip>ping 后端;
  • NFS 版本不匹配:mount.nfs: requested NFS version or transport protocol is not supported,需要在 StorageClass 里指定 mountOptions
  • 防火墙/安全组拦截 2049 等端口。

3. 文件系统类型不支持 / 需要格式化

1
MountVolume.SetUp failed: unknown filesystem type "xfs"

节点缺少对应文件系统工具(如未装 xfsprogs),需在所有节点补齐。

4. 权限问题(Permission denied / Read-only)

  • 卷被以 readOnly: true 挂载,但容器要写;
  • NFS 导出端对 root 做了 root_squash,容器内以 root 写被拒,需用 securityContext.fsGrouprunAsUser 适配。

5. subPath 用错

subPath 指向了不存在的路径、或挂载了目录却用 subPath 指向文件,都会导致挂载失败。确认 subPath 在卷内真实存在。

一个排障口诀

先看 describe pod 的 Events 定位是哪种卷;Secret/ConfigMap 看是否存在;远程存储看网络与版本;本地看文件系统工具与权限。

小结

挂载失败几乎都能从 FailedMount 的 Events + 具体卷类型反推:对象缺失、网络不通、文件系统工具缺失、权限/只读,是最常见的四类根因。