- Documentation
- Kubernetes Blog
- Training
- Partners
- Community
- Case Studies
- Versions
- Release Information
- v1.31
- v1.30
- v1.29
- v1.28
- v1.27
- English
- বাংলা (Bengali)
- 中文 (Chinese)
- Français (French)
- Deutsch (German)
- हिन्दी (Hindi)
- Bahasa Indonesia (Indonesian)
- Italiano (Italian)
- 日本語 (Japanese)
- 한국어 (Korean)
- Polski (Polish)
- Português (Portuguese)
- Русский (Russian)
- Español (Spanish)
- Українська (Ukrainian)
- Tiếng Việt (Vietnamese)
Use an Image Volume With a Pod
FEATURE STATE:
Kubernetes v1.31 [alpha]
This page shows how to configure a pod using image volumes. This allows you to mount content from OCI registries inside containers.
Before you begin
You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at least two nodes that are not acting as control plane hosts. If you do not already have a cluster, you can create one by using minikube or you can use one of these Kubernetes playgrounds:
Your Kubernetes server must be version v1.31. To check the version, enterkubectl version
.
- 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 setting the volumes.[*].image
field of .spec
to a valid reference and consuming it in the volumeMounts
of the container. For example:
apiVersion: v1
kind: Pod
metadata:
name: image-volume
spec:
containers:
- name: shell
command: ["sleep", "infinity"]
image: debian
volumeMounts:
- name: volume
mountPath: /volume
volumes:
- name: volume
image:
reference: quay.io/crio/artifact:v1
pullPolicy: IfNotPresent
-
Create the pod on your cluster:
kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml
-
Attach to the container:
kubectl attach -it image-volume bash
Run this command:
cat /volume/dir/file
The output is similar to:
1
Also run:
cat /volume/file
The output is similar to:
2
Further reading
Last modified June 24, 2024 at 10:58 AM PST: Add ImageVolume documentation (a12454f2dc)