This article is more than one year old. Older articles may contain outdated content. Check that the information in the page has not become incorrect since its publication.
Read-only volume mounts have been a feature of Kubernetes since the beginning. Surprisingly, read-only mounts are not completely read-only under certain conditions on Linux. As of the v1.30 release, they can be made completely read-only, with alpha support for recursive read-only mounts.
Volume mounts can be deceptively complicated.
You might expect that the following manifest makes everything under /mnt in the containers read-only:
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: mnt
hostPath:
path: /mnt
containers:
- volumeMounts:
- name: mnt
mountPath: /mnt
readOnly: true
However, any sub-mounts beneath /mnt may still be writable!
For example, consider that /mnt/my-nfs-server is writeable on the host.
Inside the container, writes to /mnt/* will be rejected but /mnt/my-nfs-server/* will still be writeable.
Kubernetes 1.30 added a new mount option recursiveReadOnly so as to make submounts recursively read-only.
The option can be enabled as follows:
---
apiVersion: v1
kind: Pod
spec:
volumes:
- name: mnt
hostPath:
path: /mnt
containers:
- volumeMounts:
- name: mnt
mountPath: /mnt
readOnly: true
# NEW
# Possible values are `Enabled`, `IfPossible`, and `Disabled`.
# Needs to be specified in conjunction with `readOnly: true`.
recursiveReadOnly: EnabledThis is implemented by applying the MOUNT_ATTR_RDONLY attribute with the AT_RECURSIVE flag
using mount_setattr(2) added in
Linux kernel v5.12.
For backwards compatibility, the recursiveReadOnly field is not a replacement for readOnly,
but is used in conjunction with it.
To get a properly recursive read-only mount, you must set both fields.
To enable recursiveReadOnly mounts, the following components have to be used:
Kubernetes: v1.30 or later, with the RecursiveReadOnlyMounts
feature gate enabled.
As of v1.30, the gate is marked as alpha.
CRI runtime:
OCI runtime:
Linux kernel: v5.12 or later
Kubernetes SIG Node hope - and expect - that the feature will be promoted to beta and eventually general availability (GA) in future releases of Kubernetes, so that users no longer need to enable the feature gate manually.
The default value of recursiveReadOnly will still remain Disabled, for backwards compatibility.
Please check out the documentation
for the further details of recursiveReadOnly mounts.
This feature is driven by the SIG Node community. Please join us to connect with the community and share your ideas and feedback around the above feature and beyond. We look forward to hearing from you!