website/content/en/docs/tasks/configure-pod-container/image-volumes.md

1.6 KiB

title reviewers content_type weight min-kubernetes-server-version
Use an Image Volume With a Pod task 210 v1.31

{{< 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
  • You need to enable the ImageVolume feature gate

Run a Pod that uses an image volume

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" %}}

  1. Create the pod on your cluster:

    kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml
    
  2. Attach to the container:

    kubectl attach -it image-volume bash
    
  3. Check the content of a file in the volume:

    cat /volume/dir/file
    

    The output is similar to:

    1
    

    You can also check another file in a different path:

    cat /volume/file
    

    The output is similar to:

    2
    

Further reading