4.4. 使用 Cinder 的持久性存储
OpenShift Container Platform 支持 OpenStack Cinder。我们假设您对 Kubernetes 和 OpenStack 有一定的了解。
Cinder 卷可以动态置备。持久性卷不与某个特定项目或命名空间相关联,它们可以在 OpenShift Container Platform 集群间共享。持久性卷声明是针对某个项目或者命名空间的,相应的用户可请求它。
OpenShift Container Platform 4.11 及之后的版本为 Cinder in-tree 卷插件提供自动迁移到对应的 CSI 驱动程序。
CSI 自动迁移应该可以无缝进行。迁移不会改变您使用所有现有 API 对象的方式,如持久性卷、持久性卷声明和存储类。有关迁移的更多信息,请参阅 CSI 自动迁移。
4.4.1. 使用 Cinder 手动置备 复制链接链接已复制到粘贴板!
当存储可以被挂载为 OpenShift Container Platform 中的卷之前,它必须已存在于底层的存储系统中。
先决条件
- 为 Red Hat OpenStack Platform(RHOSP)配置 OpenShift Container Platform
- Cinder 卷 ID
4.4.1.1. 创建持久性卷 复制链接链接已复制到粘贴板!
您必须在对象定义中定义持久性卷 (PV) ,然后才能在 OpenShift Container Platform 中创建它:
流程
将对象定义保存到文件中。
cinder-persistentvolume.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要在卷被格式化并置备后,不要更改
fstype
参数的值。更改此值可能会导致数据丢失和 pod 失败。创建在上一步中保存的对象定义文件。
oc create -f cinder-persistentvolume.yaml
$ oc create -f cinder-persistentvolume.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4.1.2. 持久性卷格式化 复制链接链接已复制到粘贴板!
因为 OpenShift Container Platform 在首次使用卷前会进行格式化,所以可以使用未格式化的 Cinder 卷作为 PV。
在 OpenShift Container Platform 挂载卷并将其传递给容器之前,它会检查在 PV 定义中是否包含由 fsType
参数指定的文件系统。如果没有使用文件系统格式化该设备,该设备中的所有数据都会被删除,并使用指定的文件系统自动格式化该设备。
4.4.1.3. Cinder 卷安全 复制链接链接已复制到粘贴板!
如果在应用程序中使用 Cinder PV,请在其部署配置中配置安全性。
先决条件
-
必须创建一个使用适当
fsGroup
策略的 SCC。
流程
创建一个服务帐户并将其添加到 SCC:
oc create serviceaccount <service_account>
$ oc create serviceaccount <service_account>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc adm policy add-scc-to-user <new_scc> -z <service_account> -n <project>
$ oc adm policy add-scc-to-user <new_scc> -z <service_account> -n <project>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在应用程序的部署配置中,提供服务帐户名称和
securityContext
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow