【问题标题】:access kubernetes storage from multiple pods with different modes - one pod ReadWrite, other pods ReadOnly从多个具有不同模式的 pod 访问 kubernetes 存储 - 一个 pod ReadWrite,其他 pod ReadOnly
【发布时间】:2020-07-16 19:44:20
【问题描述】:
我有一个 pod,它需要将数据持久保存到 pod 之外的位置。我认为persistentVolume 是一个好主意。名为 writerPod 的 pod 需要对该卷进行读写访问。
多个其他 Pod(我称它们为 readingPod)需要读取 writerPod 保存的文件。
是否可以有两个绑定相同 PersistentVolume 的 persistentVolumeClaims (PVC)(仅在 accessMode ReadWriteOnce 和 ReadOnlyMany 上有所不同)?
【问题讨论】:
标签:
kubernetes
google-compute-engine
persistent-volumes
【解决方案1】:
PVC 可以配置多个 accessMode(ReadOnlyMany 和 ReadWriteOnce):
accessModes:
- ReadWriteOnce
- ReadOnlyMany
但是,顾名思义,您可以在 ReadOnlyMany (AKA ROX) 中将磁盘挂载到多个 pod,但一次只能有一个 pod 在 ReadWriteOnce 模式下使用该磁盘 (AKA RWO)。
如果您的 readingPod 仅在您的 writerPod 写入其数据后才启动 - 您可以使用相同的 PVC,只需确保您安装 PVC 时将 readOnly 标志设置为 true,例如:
volumes:
- name: test-volume
persistentVolumeClaim:
claimName: my-pvc
readOnly: true
如果您使用支持 ReadWriteMany 访问模式的云提供商(不幸的是,Google 现在不是其中之一)它当然适合所有场景。查看official documentation,查看各个平台支持的模式。
【解决方案2】:
Document-1 说:ReadWriteMany:该卷可以被许多节点以读写方式挂载。由 Compute Engine 永久性磁盘支持的 PersistentVolume 不支持这种访问模式。
Document-2 表示:如果您将永久磁盘附加到多个实例,则所有这些实例都必须以只读模式附加永久磁盘。无法以读写模式将永久磁盘附加到多个实例。如果您需要在多个实例之间共享动态存储空间,您可以使用以下选项之一:
将您的实例连接到 Cloud Storage
将您的实例连接到 Filestore
在 Compute Engine 上创建网络文件服务器