GKE 上的卷声明/卷的多重附加错误卷已独占附加

Volume claim on GKE / Multi-Attach error for volume Volume is already exclusively attached

问题好像是,因为答案和评论都没有提供真正的解决方案,希望有经验的网友帮忙

错误如下(在描述 pod 时,它保持 ContainerCreating 状态):

Multi-Attach error for volume "pvc-xxx" Volume is already exclusively attached to one node and can't be attached to another 

这都是 GKE 上的 运行。我有一个以前的集群,但问题从未发生过。我在创建这个新集群时重复使用了同一个磁盘——不确定是否相关

Here is the full yaml config files(我留下相关代码部分的注释以突出显示它;它不是在有效使用时)

如果有明显的解决方法,请提前致谢

根据您的描述,您遇到的正是应该发生的情况。

您正在 PV/PVC definition 中使用 gcePersistentDiskaccessModeReadWriteOnce - 这意味着这个 PV 只能附加到单个 Node (这里强调 Node ,可以有多个 Pods 运行 在同一个 Node 上使用相同的 PV)。您对此无能为力。 gcePersistentDisk 就像一个远程块设备,不可能同时在多个 Nodes 上安装它(除非 read only)。

有一个很好的table that shows which PVs support ReadWriteMany(即同时在多个节点上写访问):

Important! A volume can only be mounted using one access mode at a time, even if it supports many. For example, a GCEPersistentDisk can be mounted as ReadWriteOnce by a single node or ReadOnlyMany by many nodes, but not at the same time.

您的 Deployment yaml 显示 5 个副本,这在 ReadWriteOnce 模式下不适用于 GCE PD。 GCE PD只能在ReadOnlyMany模式下附加到多个节点。

如果您需要跨所有副本的共享、可写存储,那么您应该研究像 NFS 或 Gluster 这样的多写入器解决方案。

如果您希望每个副本都有自己的磁盘,那么您可以使用 StatefulSets,每个副本都有一个 PVC。