本文介绍了Kubernetes持久卷访问模式:ReadWriteOnce与ReadOnlyMany与ReadWriteMany的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此官方文档,Kubernetes永久卷支持三种类型的访问模式.

As per this official document, Kubernetes Persistent Volumes support three types of access modes.

  1. ReadOnlyMany
  2. ReadWriteOnce
  3. ReadWriteMany

文档中给定的定义非常高级.如果有人可以对它们进行更详细的说明以及一些不同使用案例的示例,那就更好了.在这种情况下,我们应该使用一个对另一个.

The given definitions of them in the document is very high-level. It would be great if someone can explain them in little more detail along with some examples of different use cases where we should use one vs other.

推荐答案

当您计划将Pod不仅需要写入时,还应使用ReadWriteX. >从卷中读取数据.

You should use ReadWriteX when you plan to have Pods that will need to write to the volume, and not only read data from the volume.

当您希望Pod具有在Kubernetes集群中不同节点上运行的工作负载时能够访问给定卷的能力时,应使用XMany.这些Pod可以是属于Deployment的多个副本,也可以是完全不同的Pod.在许多情况下,希望Pod运行在不同的节点上,例如,如果您有多个Pod副本用于一个Deployment,那么即使它们中的一个发生故障,也可以在不同的节点上运行Pod副本可以帮助确保一定程度的持续可用性.或正在更新.

You should use XMany when you want the ability for Pods to access the given volume while those workloads are running on different nodes in the Kubernetes cluster. These Pods may be multiple replicas belonging to a Deployment, or may be completely different Pods. There are many cases where it's desirable to have Pods running on different nodes, for instance if you have multiple Pod replicas for a single Deployment, then having them run on different nodes can help ensure some amount of continued availability even if one of the nodes fails or is being updated.

如果您不使用XMany,但是您确实有多个需要访问给定卷的Pod,这将迫使Kubernetes将所有这些Pod安排在该卷首先安装到的任何节点上运行.如果此类Pod过多,则会使该节点超载,并且会影响其Pod需要访问该卷的Deployment的可用性,如上一段所述.

If you don't use XMany, but you do have multiple Pods that need access to the given volume, that will force Kubernetes to schedule all those Pods to run on whatever node the volume gets mounted to first, which could overload that node if there are too many such pods, and can impact the availability of Deployments whose Pods need access to that volume as explained in the previous paragraph.

所以将所有这些放在一起:

So putting all that together:

  • 如果您需要写入该卷,并且您可能需要多个Pod写入该卷,则您希望将这些Pod的灵活性安排到不同的节点,并且ReadWriteMany是给定该卷的选项K8s集群的插件,请使用ReadWriteMany.
  • 如果您需要写入该卷,但又不要求多个Pod应该能够写入该卷,或者ReadWriteMany根本不适合您使用,请使用ReadWriteOnce.
  • 如果您只需要从该卷中读取数据,并且您可能需要从该卷中读取多个Pod,则您更希望将这些Pod的灵活性安排到不同的节点,并且ReadOnlyMany是给定的选项,您的K8s群集的批量插件,请使用ReadOnlyMany.
  • 如果您只需要从卷中读取内容,或者您​​不要求多个Pod可以读取该内容,或者ReadOnlyMany根本不适合您使用,请使用ReadWriteOnce .在这种情况下,您希望该卷是只读的,但是您的卷插件的局限性迫使您选择ReadWriteOnce(没有ReadOnlyOnce选项).作为一种好习惯,请在Pod规范中考虑将containers.volumeMounts.readOnly设置为true,以将卷装载对应于打算用作只读卷的卷装载.
  • If you need to write to the volume, and you may have multiple Pods needing to write to the volume where you'd prefer the flexibility of those Pods being scheduled to different nodes, and ReadWriteMany is an option given the volume plugin for your K8s cluster, use ReadWriteMany.
  • If you need to write to the volume but either you don't have the requirement that multiple pods should be able to write to it, or ReadWriteMany simply isn't an available option for you, use ReadWriteOnce.
  • If you only need to read from the volume, and you may have multiple Pods needing to read from the volume where you'd prefer the flexibility of those Pods being scheduled to different nodes, and ReadOnlyMany is an option given the volume plugin for your K8s cluster, use ReadOnlyMany.
  • If you only need to read from the volume but either you don't have the requirement that multiple pods should be able to read from it, or ReadOnlyMany simply isn't an available option for you, use ReadWriteOnce. In this case, you want the volume to be read-only but the limitations of your volume plugin have forced you to choose ReadWriteOnce (there's no ReadOnlyOnce option). As a good practice, consider the containers.volumeMounts.readOnly setting to true in your Pod specs for volume mounts corresponding to volumes that are intended to be read-only.

这篇关于Kubernetes持久卷访问模式:ReadWriteOnce与ReadOnlyMany与ReadWriteMany的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:17