From d3c842419d326b7709f7fcb77fd454058d3070ba Mon Sep 17 00:00:00 2001 From: Mayo Date: Sun, 10 Oct 2021 11:45:34 +0800 Subject: [PATCH] [zh] update concept pv --- .../concepts/storage/persistent-volumes.md | 304 ++++++++++++++---- 1 file changed, 239 insertions(+), 65 deletions(-) diff --git a/content/zh/docs/concepts/storage/persistent-volumes.md b/content/zh/docs/concepts/storage/persistent-volumes.md index 607a899f2b..c186202548 100644 --- a/content/zh/docs/concepts/storage/persistent-volumes.md +++ b/content/zh/docs/concepts/storage/persistent-volumes.md @@ -295,13 +295,16 @@ The `Retain` reclaim policy allows for manual reclamation of the resource. When 1. 删除 PersistentVolume 对象。与之相关的、位于外部基础设施中的存储资产 (例如 AWS EBS、GCE PD、Azure Disk 或 Cinder 卷)在 PV 删除之后仍然存在。 1. 根据情况,手动清除所关联的存储资产上的数据。 -1. 手动删除所关联的存储资产;如果你希望重用该存储资产,可以基于存储资产的 - 定义创建新的 PersistentVolume 卷对象。 +1. 手动删除所关联的存储资产。 + +如果你希望重用该存储资产,可以基于存储资产的定义创建新的 PersistentVolume 卷对象。 * [`awsElasticBlockStore`](/zh/docs/concepts/storage/volumes/#awselasticblockstore) - AWS 弹性块存储(EBS) * [`azureDisk`](/zh/docs/concepts/storage/volumes/#azuredisk) - Azure Disk * [`azureFile`](/zh/docs/concepts/storage/volumes/#azurefile) - Azure File * [`cephfs`](/zh/docs/concepts/storage/volumes/#cephfs) - CephFS volume -* [`cinder`](/zh/docs/concepts/storage/volumes/#cinder) - Cinder (OpenStack 块存储) - (**弃用**) * [`csi`](/zh/docs/concepts/storage/volumes/#csi) - 容器存储接口 (CSI) * [`fc`](/zh/docs/concepts/storage/volumes/#fc) - Fibre Channel (FC) 存储 * [`flexVolume`](/zh/docs/concepts/storage/volumes/#flexVolume) - FlexVolume -* [`flocker`](/zh/docs/concepts/storage/volumes/#flocker) - Flocker 存储 * [`gcePersistentDisk`](/zh/docs/concepts/storage/volumes/#gcepersistentdisk) - GCE 持久化盘 * [`glusterfs`](/zh/docs/concepts/storage/volumes/#glusterfs) - Glusterfs 卷 * [`hostPath`](/zh/docs/concepts/storage/volumes/#hostpath) - HostPath 卷 @@ -661,16 +651,45 @@ PV 持久卷是用插件的形式来实现的。Kubernetes 目前支持以下插 * [`iscsi`](/zh/docs/concepts/storage/volumes/#iscsi) - iSCSI (SCSI over IP) 存储 * [`local`](/zh/docs/concepts/storage/volumes/#local) - 节点上挂载的本地存储设备 * [`nfs`](/zh/docs/concepts/storage/volumes/#nfs) - 网络文件系统 (NFS) 存储 -* `photonPersistentDisk` - Photon 控制器持久化盘。 - (这个卷类型已经因对应的云提供商被移除而被弃用)。 * [`portworxVolume`](/zh/docs/concepts/storage/volumes/#portworxvolume) - Portworx 卷 -* [`quobyte`](/zh/docs/concepts/storage/volumes/#quobyte) - Quobyte 卷 * [`rbd`](/zh/docs/concepts/storage/volumes/#rbd) - Rados 块设备 (RBD) 卷 -* [`scaleIO`](/zh/docs/concepts/storage/volumes/#scaleio) - ScaleIO 卷 - (**弃用**) -* [`storageos`](/zh/docs/concepts/storage/volumes/#storageos) - StorageOS 卷 * [`vsphereVolume`](/zh/docs/concepts/storage/volumes/#vspherevolume) - vSphere VMDK 卷 + + +以下的持久卷已被弃用。这意味着当前仍是支持的,但是 Kubernetes 将来的发行版会将其移除。 + +* [`cinder`](/docs/concepts/storage/volumes/#cinder) - Cinder(OpenStack 块存储)(于 v1.18 **弃用**) +* [`flocker`](/docs/concepts/storage/volumes/#flocker) - Flocker 存储(于 v1.22 **弃用**) +* [`quobyte`](/docs/concepts/storage/volumes/#quobyte) - Quobyte 卷 +(于 v1.22 **弃用**) +* [`storageos`](/docs/concepts/storage/volumes/#storageos) - StorageOS 卷(于 v1.22 **弃用**) + + + +旧版本的 Kubernetes 仍支持这些“树内(In-Tree)”持久卷类型: + +* `photonPersistentDisk` - Photon 控制器持久化盘。(v1.15 之后 **不可用**) +* [`scaleIO`](/docs/concepts/storage/volumes/#scaleio) - ScaleIO 卷(v1.21 之后 **不可用**) + 访问模式有: -* ReadWriteOnce -- 卷可以被一个节点以读写方式挂载; -* ReadOnlyMany -- 卷可以被多个节点以只读方式挂载; -* ReadWriteMany -- 卷可以被多个节点以读写方式挂载。 +`ReadWriteOnce` +: 卷可以被一个节点以读写方式挂载。 +ReadWriteOnce 访问模式也允许运行在同一节点上的多个 Pod 访问卷。 + +`ReadOnlyMany` +: 卷可以被多个节点以只读方式挂载。 + +`ReadWriteMany` +: 卷可以被多个节点以读写方式挂载。 + +`ReadWriteOncePod` +: 卷可以被单个 Pod 以读写方式挂载。 +如果你想确保整个集群中只有一个 Pod 可以读取或写入该 PVC, +请使用ReadWriteOncePod 访问模式。这只支持 CSI 卷以及需要 Kubernetes 1.22 以上版本。 + +这篇博客文章 [Introducing Single Pod Access Mode for PersistentVolumes](/blog/2021/09/13/read-write-once-pod-access-mode-alpha/) +描述了更详细的内容。 在命令行接口(CLI)中,访问模式也使用以下缩写形式: * RWO - ReadWriteOnce * ROX - ReadOnlyMany * RWX - ReadWriteMany +* RWOP - ReadWriteOncePod -> __重要提醒!__ 每个卷只能同一时刻只能以一种访问模式挂载,即使该卷能够支持 +> __重要提醒!__ 每个卷同一时刻只能以一种访问模式挂载,即使该卷能够支持 > 多种访问模式。例如,一个 GCEPersistentDisk 卷可以被某节点以 ReadWriteOnce > 模式挂载,或者被多个节点以 ReadOnlyMany 模式挂载,但不可以同时以两种模式 > 挂载。 @@ -826,28 +871,27 @@ In the CLI, the access modes are abbreviated to: | Volume Plugin | ReadWriteOnce | ReadOnlyMany | ReadWriteMany| --> -| 卷插件 | ReadWriteOnce | ReadOnlyMany | ReadWriteMany| -| :--- | :---: | :---: | :---: | -| AWSElasticBlockStore | ✓ | - | - | -| AzureFile | ✓ | ✓ | ✓ | -| AzureDisk | ✓ | - | - | -| CephFS | ✓ | ✓ | ✓ | -| Cinder | ✓ | - | - | -| CSI | 取决于驱动 | 取决于驱动 | 取决于驱动 | -| FC | ✓ | ✓ | - | -| FlexVolume | ✓ | ✓ | 取决于驱动 | -| Flocker | ✓ | - | - | -| GCEPersistentDisk | ✓ | ✓ | - | -| Glusterfs | ✓ | ✓ | ✓ | -| HostPath | ✓ | - | - | -| iSCSI | ✓ | ✓ | - | -| Quobyte | ✓ | ✓ | ✓ | -| NFS | ✓ | ✓ | ✓ | -| RBD | ✓ | ✓ | - | -| VsphereVolume | ✓ | - | - (Pod 运行于同一节点上时可行) | -| PortworxVolume | ✓ | - | ✓ | -| ScaleIO | ✓ | ✓ | - | -| StorageOS | ✓ | - | - | +| 卷插件 | ReadWriteOnce | ReadOnlyMany | ReadWriteMany | ReadWriteOncePod | +| :--- | :---: | :---: | :---: | - | +| AWSElasticBlockStore | ✓ | - | - | - | +| AzureFile | ✓ | ✓ | ✓ | - | +| AzureDisk | ✓ | - | - | - | +| CephFS | ✓ | ✓ | ✓ | - | +| Cinder | ✓ | - | - | - | +| CSI | 取决于驱动 | 取决于驱动 | 取决于驱动 | 取决于驱动 | +| FC | ✓ | ✓ | - | - | +| FlexVolume | ✓ | ✓ | 取决于驱动 | - | +| Flocker | ✓ | - | - | - | +| GCEPersistentDisk | ✓ | ✓ | - | - | +| Glusterfs | ✓ | ✓ | ✓ | - | +| HostPath | ✓ | - | - | - | +| iSCSI | ✓ | ✓ | - | - | +| Quobyte | ✓ | ✓ | ✓ | - | +| NFS | ✓ | ✓ | ✓ | - | +| RBD | ✓ | ✓ | - | - | +| VsphereVolume | ✓ | - | - (Pod 运行于同一节点上时可行) | - | +| PortworxVolume | ✓ | - | ✓ | - | - | +| StorageOS | ✓ | - | - | - | -每个 PV 卷可以通过设置 -[节点亲和性](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volumenodeaffinity-v1-core) -来定义一些约束,进而限制从哪些节点上可以访问此卷。 +每个 PV 卷可以通过设置节点亲和性来定义一些约束,进而限制从哪些节点上可以访问此卷。 使用这些卷的 Pod 只会被调度到节点亲和性规则所选择的节点上执行。 +要设置节点亲和性,配置 PV 卷 `.spec` 中的 `nodeAffinity`。 +[持久卷](/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-v1/#PersistentVolumeSpec) +API 参考关于该字段的更多细节。 + +## 卷填充器(Populator)与数据源 {#volume-populators-and-data-sources} + +{{< feature-state for_k8s_version="v1.22" state="alpha" >}} + +{{< note >}} +Kubernetes 支持自定义的卷填充器;Kubernetes 1.18 版本引入了这个 alpha 特性。 +Kubernetes 1.22 使用重新设计的 API 重新实现了该机制。 +确认你正在阅读与你的集群版本一致的 Kubernetes 文档。{{% version-check %}} +要使用自定义的卷填充器,你必须为 kube-apiserver 和 kube-controller-manager 启用 `AnyVolumeDataSource` +[特性门控](/zh/docs/reference/command-line-tools-reference/feature-gates/)。 +{{< /note >}} + +卷填充器利用了 PVC 规约字段 `dataSourceRef`。 +不像 `dataSource` 字段只能包含对另一个持久卷申领或卷快照的引用, +`dataSourceRef` 字段可以包含对同一命名空间中任何对象的引用(不包含除 PVC 以外的核心资源)。 +对于启用了特性门控的集群,使用 `dataSourceRef` 比 `dataSource` 更好。 + + + +## 数据源引用 {#data-source-references} + +`dataSourceRef` 字段的行为与 `dataSource` 字段几乎相同。 +如果其中一个字段被指定而另一个字段没有被指定,API 服务器将给两个字段相同的值。 +这两个字段都不能在创建后改变,如果试图为这两个字段指定不同的值,将导致验证错误。 +因此,这两个字段将总是有相同的内容。 + + +在 `dataSourceRef` 字段和 `dataSource` 字段之间有两个用户应该注意的区别: +* `dataSource` 字段会忽略无效的值(如同是空值), + 而 `dataSourceRef` 字段永远不会忽略值,并且若填入一个无效的值,会导致错误。 + 无效值指的是 PVC 之外的核心对象(没有 apiGroup 的对象)。 +* `dataSourceRef` 字段可以包含不同类型的对象,而 `dataSource` 字段只允许 PVC 和卷快照。 + +用户应该始终在启用了特性门控的集群上使用 `dataSourceRef`,而在没有启用特性门控的集群上使用 `dataSource`。 +在任何情况下都没有必要查看这两个字段。 +这两个字段的值看似相同但是语义稍微不一样,是为了向后兼容。 +特别是混用旧版本和新版本的控制器时,它们能够互通。 + + +## 使用卷填充器 {#using-volume-populators} + +卷填充器是能创建非空卷的{{< glossary_tooltip text="控制器" term_id="controller" >}}, +其卷的内容通过一个自定义资源决定。 +用户通过使用 `dataSourceRef` 字段引用自定义资源来创建一个被填充的卷: + +```yaml +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: populated-pvc +spec: + dataSourceRef: + name: example-name + kind: ExampleDataSource + apiGroup: example.storage.k8s.io + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi +``` + + +因为卷填充器是外部组件,如果没有安装所有正确的组件,试图创建一个使用卷填充器的 PVC 就会失败。 +外部控制器应该在 PVC 上产生事件,以提供创建状态的反馈,包括在由于缺少某些组件而无法创建 PVC 的情况下发出警告。 + +你可以把 alpha 版本的[卷数据源验证器](https://github.com/kubernetes-csi/volume-data-source-validator) +控制器安装到你的集群中。 +如果没有填充器处理该数据源的情况下,该控制器会在 PVC 上产生警告事件。 +当一个合适的填充器被安装到 PVC 上时,该控制器的职责是上报与卷创建有关的事件,以及在该过程中发生的问题。 + @@ -1506,16 +1680,16 @@ and need persistent storage, it is recommended that you use the following patter * 阅读[持久存储的设计文档](https://git.k8s.io/community/contributors/design-proposals/storage/persistent-storage.md). -### 参考 {#reference} +### API 参考 {#reference} -* [PersistentVolume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolume-v1-core) -* [PersistentVolumeSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumespec-v1-core) -* [PersistentVolumeClaim](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaim-v1-core) -* [PersistentVolumeClaimSpec](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#persistentvolumeclaimspec-v1-core) +阅读以下页面中描述的 API: + +* [`PersistentVolume`](/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-v1/) +* [`PersistentVolumeClaim`](/docs/reference/kubernetes-api/config-and-storage-resources/persistent-volume-claim-v1/)