apiVersion: "v1"
kind: "PersistentVolume"
metadata:
name: "pv0001" (1)
spec:
capacity:
storage: "5Gi" (2)
accessModes:
- "ReadWriteOnce"
cinder: (3)
fsType: "ext3" (4)
volumeID: "f37a03aa-6212-4c62-a805-9ce139fab180" (5)
OpenShift Container Platform 支持 OpenStack Cinder。假设您已熟悉 Kubernetes 和 OpenStack。
Cinder 卷可以动态配置。持久卷不会绑定到单个项目或命名空间;它们可以在 OpenShift Container Platform 集群中共享。持久卷声明特定于一个项目或命名空间,用户可以请求它们。
OpenShift Container Platform 4.11 及更高版本为 Cinder 内置卷插件提供到其等效 CSI 驱动的自动迁移。 CSI 自动迁移应该无缝进行。迁移不会更改您如何使用所有现有 API 对象,例如持久卷、持久卷声明和存储类。有关迁移的更多信息,请参阅 CSI 自动迁移。 |
有关 OpenStack 块存储如何为虚拟硬盘驱动器提供持久块存储管理的更多信息,请参阅 OpenStack Cinder。
存储必须存在于底层基础架构中,然后才能将其作为卷安装到 OpenShift Container Platform 中。
配置为 Red Hat OpenStack Platform (RHOSP) 的 OpenShift Container Platform
Cinder 卷 ID
您必须在 OpenShift Container Platform 中创建持久卷 (PV) 之前在对象定义中定义它。
将对象定义保存到文件。
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
name: "pv0001" (1)
spec:
capacity:
storage: "5Gi" (2)
accessModes:
- "ReadWriteOnce"
cinder: (3)
fsType: "ext3" (4)
volumeID: "f37a03aa-6212-4c62-a805-9ce139fab180" (5)
1 | 持久卷声明或 Pod 使用的卷的名称。 |
2 | 分配给此卷的存储量。 |
3 | 指示 Red Hat OpenStack Platform (RHOSP) Cinder 卷的 cinder 。 |
4 | 卷首次安装时创建的文件系统。 |
5 | 要使用的 Cinder 卷。 |
卷格式化和配置后,请勿更改 |
创建您在上一步中保存的对象定义文件。
$ oc create -f cinder-persistentvolume.yaml
您可以使用未格式化的 Cinder 卷作为 PV,因为 OpenShift Container Platform 会在第一次使用前对其进行格式化。
在 OpenShift Container Platform 安装卷并将其传递给容器之前,系统会检查它是否包含 PV 定义中 fsType
参数指定的文件系统。如果设备未使用该文件系统进行格式化,则会擦除设备中的所有数据,并使用给定的文件系统自动格式化设备。
如果在应用程序中使用 Cinder PV,请为其部署配置配置安全。
必须创建一个使用适当 fsGroup
策略的 SCC。
创建一个服务帐户并将其添加到 SCC
$ oc create serviceaccount <service_account>
$ oc adm policy add-scc-to-user <new_scc> -z <service_account> -n <project>
在应用程序的部署配置中,提供服务帐户名称和 securityContext
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend-1
spec:
replicas: 1 (1)
selector: (2)
name: frontend
template: (3)
metadata:
labels: (4)
name: frontend (5)
spec:
containers:
- image: openshift/hello-openshift
name: helloworld
ports:
- containerPort: 8080
protocol: TCP
restartPolicy: Always
serviceAccountName: <service_account> (6)
securityContext:
fsGroup: 7777 (7)
1 | 要运行的 Pod 的副本数。 |
2 | 要运行的 Pod 的标签选择器。 |
3 | 控制器创建的 Pod 的模板。 |
4 | Pod上的标签。它们必须包含来自标签选择器的标签。 |
5 | 展开任何参数后的最大名称长度为 63 个字符。 |
6 | 指定您创建的服务帐户。 |
7 | 为 Pod 指定一个fsGroup 。 |