30

Kubernetes 似乎支持 3 种持久卷的访问模式:ReadWriteOnce, ReadOnlyMany, ReadWriteMany. 我真的很好奇使用ReadWriteOnce模式卷的 pod 的调度策略。例如,我创建了一个 pod num=2 的 RC,我猜这两个 pod 将被调度到同一主机,因为它们使用具有ReadWriteOnce模式的卷?我很想知道这部分的源代码。

4

3 回答 3

20

我认为赞成的答案是错误的。根据访问模式上的 Kubernetes 文档

访问模式有:

  • ReadWriteOnce -- 卷可以被单个节点以读写方式挂载
  • ReadOnlyMany -- 卷可以被许多节点以只读方式挂载
  • ReadWriteMany -- 卷可以被许多节点以读写方式挂载

因此,今天定义的 AccessModes 仅描述节点附加(而不是 pod 挂载)语义,并且不强制执行任何操作。

因此,为了防止两个 Pod 挂载相同的 PVC,即使它们被安排在同一个节点上运行,您也可以使用 Pod 反亲和性。这与不将一个卷挂载到同一节点上调度的 2 个 Pod 是不一样的。但是可以使用反亲和性来要求调度程序不要在同一个节点上运行 2 个 pod。因此,它可以防止将一个卷安装到 2 个 pod 中。

于 2021-01-01T18:03:43.393 回答
13

如果一个 pod 挂载了一个具有ReadWriteOnce访问模式的卷,则没有其他 pod 可以挂载它。在 GCE(Google Compute Engine)中,唯一允许的模式是ReadWriteOnceReadOnlyMany。因此,要么一个 pod 挂载该卷ReadWrite,要么一个或多个 pod 挂载该卷ReadOnlyMany

如果 Pod 使用已经以读写方式挂载的 GCE 卷,则调度程序(此处的代码)将不允许 Pod 进行调度。

(不理解问题的人的文档参考: 持久卷访问模式

于 2016-06-06T05:35:16.140 回答
-1

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.

于 2022-02-09T09:22:33.660 回答