默认情况下,只读卷装载并不是真正的只读
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: mnt
hostPath:
path: /mnt
containers:
- volumeMounts:
- name: mnt
mountPath: /mnt
readOnly: true
/mnt
下的任何子挂载仍然是可写的!
Kubernetes 1.30 添加了一个新的挂载选项 recursiveReadOnly,以使子挂载递归只读。
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: mnt
hostPath:
path: /mnt
containers:
- volumeMounts:
- name: mnt
mountPath: /mnt
readOnly: true
# NEW
# 可能的值为 `Enabled`、`IfPossible` 和 `Disabled`。
# 需要与 `readOnly: true` 一起指定。
recursiveReadOnly: Enabled
要获得正确的递归只读挂载,你必须设置这两个字段。
要启用 recursiveReadOnly 挂载,必须使用以下组件:
-
Kubernetes:v1.30 或更新版本,并启用 RecursiveReadOnlyMounts 特性门控。从 v1.30 开始,此特性被标记为 Alpha。<