7.2. 在 PVC 中请求持久性存储
在以下情况下,您可以选择应用 PersistentVolumeClaim (PVC)为工作区请求 PersistentVolume (PV):
- 不是项目中的所有开发人员都需要 PV。
- PV 生命周期超过单个工作区的生命周期。
- PV 中包含的数据在工作区之间共享。
即使工作区是临时的,并且其 devfile 包含 controller.devfile.io/storage-type: ephemeral 属性,您也可以将 PVC 应用到 Dev Workspace 容器。
先决条件
- 您没有启动工作区。
-
一个活跃的
oc会话,它具有到目标 OpenShift 集群的管理权限。请参阅开始使用 CLI。 -
在用户项目中创建 PVC 以挂载到所有
Dev Workspace容器。
流程
将
controller.devfile.io/mount-to-devworkspace: true标签添加到 PVC。$ oc label persistentvolumeclaim <PVC_name> \ controller.devfile.io/mount-to-devworkspace=true可选: 使用注解来配置 PVC 的挂载方式:
Expand 表 7.1. 可选注解 注解 描述 controller.devfile.io/mount-path:PVC 的挂载路径。
默认为
/tmp/<PVC_name>。controller.devfile.io/read-only:设置为
'true'或'false',以指定 PVC 是否挂载为只读。默认为
'false',从而导致 PVC 挂载为读写。
例 7.2. 挂载只读 PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: <pvc_name>
labels:
controller.devfile.io/mount-to-devworkspace: 'true'
annotations:
controller.devfile.io/mount-path: </example/directory>
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
volumeName: <pv_name>
storageClassName: manual
volumeMode: Filesystem