Use an Image Volume With a Pod
Kubernetes Docs · نسخهٔ f284a9e7c87f · CC BY 4.0 برای مستندات و مجوزهای همراه
<!-- overview -->
{{< feature-state feature_gate_name="ImageVolume" >}}
This page shows how to configure a pod using image volumes. This allows you to mount content from OCI registries inside containers.
{{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
- The container runtime needs to support the image volumes feature
- You need to exec commands in the host
- You need to be able to exec into pods
<!-- steps -->
Run a Pod that uses an image volume {#create-pod}
An image volume for a pod is enabled by setting the volumes[*].image field of .spec to a valid reference and consuming it in the volumeMounts of the container. For example:
{{% code_sample file="pods/image-volumes.yaml" %}}
- Create the pod on your cluster:
kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml- Attach to the container:
kubectl exec image-volume -it -- bash- Check the content of a file in the volume:
cat /volume/dir/fileThe output is similar to:
1You can also check another file in a different path:
cat /volume/fileThe output is similar to:
2Use subPath (or subPathExpr)
It is possible to utilize [subPath](/docs/concepts/storage/volumes/#using-subpath) or [subPathExpr](/docs/concepts/storage/volumes/#using-subpath-expanded-environment) from Kubernetes v1.33 when using the image volume feature.
{{% code_sample file="pods/image-volumes-subpath.yaml" %}}
- Create the pod on your cluster:
kubectl apply -f https://k8s.io/examples/pods/image-volumes-subpath.yaml- Attach to the container:
kubectl exec image-volume -it -- bash- Check the content of the file from the
dirsub path in the volume:
cat /volume/fileThe output is similar to:
1Further reading
- [
imagevolumes](/docs/reference/storage/volume-types/#image)