|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.33: Image Volumes graduate to beta!" |
| 4 | +date: 2025-05-01 |
| 5 | +slug: image-voume-beta |
| 6 | +author: Sascha Grunert (Red Hat) |
| 7 | +--- |
| 8 | + |
| 9 | +[Image Volumes](/blog/2024/08/16/kubernetes-1-31-image-volume-source) were |
| 10 | +introduced as an Alpha feature with the Kubernetes v1.31 release as part of |
| 11 | +[KEP-4639](https://github.com/kubernetes/enhancements/issues/4639). The recent |
| 12 | +release of Kubernetes v1.33 moved that support to **beta**. |
| 13 | + |
| 14 | +Please note that the feature is still _disabled_ by default, because not all |
| 15 | +[container runtimes](/docs/setup/production-environment/container-runtimes) have |
| 16 | +full support for it. [CRI-O](https://cri-o.io) supports the initial feature since version v1.31 and |
| 17 | +will add support for Image Volumes as beta in v1.33. |
| 18 | +[containerd merged](https://github.com/containerd/containerd/pull/10579) support |
| 19 | +for the alpha feature which will be part of the v2.1.0 release and is working on |
| 20 | +beta support as part of [PR #11578](https://github.com/containerd/containerd/pull/11578). |
| 21 | + |
| 22 | +### What's new |
| 23 | + |
| 24 | +The major change for the beta graduation of Image Volumes is the support for |
| 25 | +[`subPath`](/docs/concepts/storage/volumes/#using-subpath) and |
| 26 | +[`subPathExpr`](/docs/concepts/storage/volumes/#using-subpath-expanded-environment) mounts |
| 27 | +for containers via `spec.containers[*].volumeMounts.[subPath,subPathExpr]`. This |
| 28 | +allows end-users to mount a certain subdirectory of an image volume, which is |
| 29 | +still mounted as readonly (`noexec`). This means that non-existing |
| 30 | +subdirectories cannot be mounted by default. As for other `subPath` and |
| 31 | +`subPathExpr` values, Kubernetes will ensure that there are no absolute path or |
| 32 | +relative path components part of the specified sub path. Container runtimes are |
| 33 | +also required to double check those requirements for safety reasons. If a |
| 34 | +specified subdirectory does not exist within a volume, then runtimes should fail |
| 35 | +on container creation and provide user feedback by using existing kubelet |
| 36 | +events. |
| 37 | + |
| 38 | +There are also three new kubelet metrics available for image volumes: |
| 39 | + |
| 40 | +- `kubelet_image_volume_requested_total`: Outlines the number of requested image volumes. |
| 41 | +- `kubelet_image_volume_mounted_succeed_total`: Counts the number of successful image volume mounts. |
| 42 | +- `kubelet_image_volume_mounted_errors_total`: Accounts the number of failed image volume mounts. |
| 43 | + |
| 44 | +To use an existing subdirectory for a specific image volume, just use it as |
| 45 | +`subPath` value of the containers `volumeMounts`: |
| 46 | + |
| 47 | +{{% code_sample file="pods/image-volumes-subpath.yaml" %}} |
| 48 | + |
| 49 | +1. Create the pod on your cluster: |
| 50 | + |
| 51 | + ```shell |
| 52 | + kubectl apply -f https://k8s.io/examples/pods/image-volumes-subpath.yaml |
| 53 | + ``` |
| 54 | + |
| 55 | +1. Attach to the container: |
| 56 | + |
| 57 | + ```shell |
| 58 | + kubectl attach -it image-volume bash |
| 59 | + ``` |
| 60 | + |
| 61 | +1. Check the content of the file from the `dir` sub path in the volume: |
| 62 | + |
| 63 | + ```shell |
| 64 | + cat /volume/file |
| 65 | + ``` |
| 66 | + |
| 67 | + The output is similar to: |
| 68 | + |
| 69 | + ```none |
| 70 | + 1 |
| 71 | + ``` |
0 commit comments