From f5f7e14118a29677fc0133fcfee9301b7a20120a Mon Sep 17 00:00:00 2001 From: "xin.li" Date: Sat, 5 Sep 2026 20:55:11 +0800 Subject: [PATCH] [zh-cn]sync volumes Signed-off-by: xin.li --- .../zh-cn/docs/concepts/storage/volumes.md | 219 +++++++++++++++++- 1 file changed, 217 insertions(+), 2 deletions(-) diff --git a/content/zh-cn/docs/concepts/storage/volumes.md b/content/zh-cn/docs/concepts/storage/volumes.md index eeafca5f12198..2dc3d07abfb00 100644 --- a/content/zh-cn/docs/concepts/storage/volumes.md +++ b/content/zh-cn/docs/concepts/storage/volumes.md @@ -355,6 +355,34 @@ for points to note in terms of resource management when using memory-backed `emp 了解有关资源管理方面的注意事项。 {{< /caution >}} +{{< feature-state feature_gate_name="EmptyDirVolumeMode" >}} + + +`emptyDir.mode` 字段用于设置 emptyDir 目录的 Unix 权限位,取值范围为 `0000` +到 `01777`(八进制)。与 Secret 和 ConfigMap 卷上的 `defaultMode` 字段用法一致。 +如果未指定 `mode`,则目录将以默认的 `0777` 权限创建。 + +设置自定义模式适用于以下场景:仅允许属主和属组访问(例如 `0750`),或在共享目录上设置粘滞位, +使得只有文件属主才能删除自己的文件(例如 `01777`)。 + +{{< note >}} + +如果在 Pod 的安全上下文中设置了 `fsGroup`,则 `fsGroup` 所应用的组权限会覆盖此处指定的 `mode`。 +`mode` 字段在 Windows 上无效。 +{{< /note >}} + @@ -402,6 +430,67 @@ spec: medium: Memory ``` +{{< note >}} +{{< feature-state feature_gate_name="InPlacePodVerticalScalingMemoryBackedVolumes" >}} + + +启用 `InPlacePodVerticalScalingMemoryBackedVolumes` 特性门控后, +你可以动态调整基于内存的(`medium: Memory`)`emptyDir` 卷的 `sizeLimit`,而无需重启 Pod。 +有关详情,请参阅[调整分配给容器的 CPU 和内存资源](/zh-cn/docs/tasks/configure-pod-container/resize-container-resources/resizing-memory-backed-emptydir-volumes)。 +{{< /note >}} + + +#### emptyDir 权限配置示例 + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: volume-user-fields-example +spec: + containers: + - name: test + image: busybox:1.28 + command: ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null'] + volumeMounts: + - name: volA + mountPath: /mnt/volA + - name: volB + mountPath: /mnt/volB + - name: volC + mountPath: /mnt/volC + volumes: + - name: volA + configMap: + defaultUser: 1000 + name: cm1 + items: + - key: foo # Owner=defaultUser + path: foo + - key: bar # Owner=user + path: bar + user: 1001 + - name: volB + secret: # Owner=defaultUser + defaultUser: 1000 + secretName: secret1 + - name: volC + projected: + sources: + - secret: + name: secret2 + items: + - key: moo # Owner=root + path: moo + - key: baa # Owner=user + path: baa + user: 1000 +``` + 当此属性被 kubelet 和 kube-apiserver 识别到时, `.status.containerStatuses[*].volumeMounts[*].recursiveReadOnly` 字段将被设置为 `Enabled` 或 `Disabled`。 + +## 文件属主 + +### 属组(GID) + +卷文件的属组(GID)由 Pod 的 `spec.securityContext.fsGroup` 控制。 + +有关详细配置步骤,请参阅[为 Pod 或容器配置安全上下文](/zh-cn/docs/tasks/configure-pod-container/security-context/)。 + +### 属主(UID) + +{{< feature-state feature_gate_name="AtomicWriteVolumeUserFields" >}} + + +启用 `AtomicWriteVolumeUserFields` +[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)后,将为 +`configMap`、`secret`、`downwardAPI` 和 `projected` 卷启用文件属主(UID)字段。 + +在卷级别指定 `defaultUser` 时,会在创建时设置该卷所有数据文件的属主 UID。 +在项级别,`user` 字段控制单个文件的属主 UID,且优先于 `defaultUser`。 + +示例: + +```yaml +apiVersion: v1 +kind: Pod +metadata: + name: volume-user-fields-example +spec: + containers: + - name: test + image: busybox:1.28 + command: ['sh', '-c', 'echo "The app is running!" && tail -f /dev/null'] + volumeMounts: + - name: volA + mountPath: /mnt/volA + - name: volB + mountPath: /mnt/volB + - name: volC + mountPath: /mnt/volC + volumes: + - name: volA + configMap: + defaultUser: 1000 + name: cm1 + items: + - key: foo # Owner=defaultUser + path: foo + - key: bar # Owner=user + path: bar + user: 1001 + - name: volB + secret: # Owner=defaultUser + defaultUser: 1000 + secretName: secret1 + - name: volC + projected: + sources: + - secret: + name: secret2 + items: + - key: moo # Owner=root + path: moo + - key: baa # Owner=user + path: baa + user: 1000 +``` + + #### 实现 {#implementations-rro} {{% thirdparty-content %}} @@ -2187,6 +2364,44 @@ OCI 级别: - [runc](https://runc.io/),自 v1.1 起 - [crun](https://github.com/containers/crun),自 v1.8.6 起 + +## 绑定挂载选项 + +{{< feature-state feature_gate_name="VolumeBindMountOptions" >}} + + +`.spec.containers[*].volumeMounts[*].bindMountOptions` 字段用于将安全相关的 +Linux bind 挂载标志应用于任何卷挂载。允许的值为: + +* `noexec` - 禁止在已挂载卷上执行二进制文件 +* `nodev` - 忽略已挂载卷上的设备特殊文件 +* `nosuid` - 忽略已挂载卷上的 set-user-identifier(SUID)和 set-group-identifier(SGID)位 + +这些选项按容器分别生效,因此同一 Pod 中的不同容器可以以不同的 bind 挂载选项挂载同一卷。该字段不支持用于[镜像卷](#image)。 + +{{< note >}} + +容器运行时(如 containerd 或 CRI-O)必须支持 CRI `Mount` 消息中的 `mount_options` 字段。 +如果运行时未声明支持此字段,kubelet 会拒绝使用 `bindMountOptions` 的 Pod。该字段在 Windows 节点上无效。 +{{< /note >}} + ## {{% heading "whatsnext" %}}