Kubernetes 似乎支持 3 种持久卷的访问模式:ReadWriteOnce
, ReadOnlyMany
, ReadWriteMany
. 我真的很好奇使用ReadWriteOnce
模式卷的 pod 的调度策略。例如,我创建了一个 pod num=2 的 RC,我猜这两个 pod 将被调度到同一主机,因为它们使用具有ReadWriteOnce
模式的卷?我很想知道这部分的源代码。
3 回答
我认为赞成的答案是错误的。根据访问模式上的 Kubernetes 文档
访问模式有:
- ReadWriteOnce -- 卷可以被单个节点以读写方式挂载
- ReadOnlyMany -- 卷可以被许多节点以只读方式挂载
- ReadWriteMany -- 卷可以被许多节点以读写方式挂载
因此,今天定义的 AccessModes 仅描述节点附加(而不是 pod 挂载)语义,并且不强制执行任何操作。
因此,为了防止两个 Pod 挂载相同的 PVC,即使它们被安排在同一个节点上运行,您也可以使用 Pod 反亲和性。这与不将一个卷挂载到同一节点上调度的 2 个 Pod 是不一样的。但是可以使用反亲和性来要求调度程序不要在同一个节点上运行 2 个 pod。因此,它可以防止将一个卷安装到 2 个 pod 中。
In Kubernetes you provision storage either statically(using a storage class) or dynamically (Persistent Volume). Once the storage is available to bound and claimed, you need to configure it in what way your Pods or Nodes are connecting to the storage (a persistent volume). That could be configured in below four modes.
ReadOnlyMany (ROX)
In this mode multiple pods running on different Nodes could connect to the storage and carry out read operation.
ReadWriteMany (RWX)
In this mode multiple pods running on different Nodes could connect to the storage and carry out read and write operation.
ReadWriteOnce (RWO)
In this mode multiple pods running in only one Node could connect to the storage and carry out read and write operation.
ReadWriteOncePod (RWOP)
In this mode the volume can be mounted as read-write by a single Pod. Use ReadWriteOncePod access mode if you want to ensure that only one pod across whole cluster can read that PVC or write to it. This is only supported for CSI volumes and Kubernetes version 1.22+.
Follow the documentation to get more insight.