7.2. 在 PVC 中请求持久性存储


在以下情况下,您可以选择应用 PersistentVolumeClaim (PVC)来为您的工作区请求 PersistentVolume (PV):

  • 并非所有项目开发人员都需要 PV。
  • PV 生命周期超出了一个工作区的生命周期。
  • PV 中包含的数据在工作区间共享。
提示

即使工作区是临时的,并且其 devfile 包含 controller.devfile.io/storage-type: ephemeral 属性,也可以将 PVC 应用到 Dev Workspace 容器。

先决条件

  • 您尚未启动工作区。
  • 对目标 OpenShift 集群具有管理权限的活动 oc 会话。请参阅 CLI 入门
  • 在用户项目中创建一个 PVC,以挂载到所有 Dev Workspace 容器。

流程

  1. controller.devfile.io/mount-to-devworkspace: true 标签添加到 PVC。

    $ oc label persistentvolumeclaim <PVC_name> \ controller.devfile.io/mount-to-devworkspace=true$ oc label persistentvolumeclaim <PVC_name> \ controller.devfile.io/mount-to-devworkspace=true$ oc label persistentvolumeclaim <PVC_name> \ controller.devfile.io/mount-to-devworkspace=true
    Copy to Clipboard Toggle word wrap
  2. 可选:使用注解来配置如何挂载 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> 
1

    controller.devfile.io/read-only: 'true'
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi 
2

  storageClassName: <storage_class_name> 
3

  volumeMode: Filesystem
Copy to Clipboard Toggle word wrap
1
挂载的 PV 位于工作区的 </example/directory>
2
请求存储的大小值示例。
3
声明所需的 StorageClass 的名称。如果要使用默认 StorageClass,请删除此行。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat