2.11.2. Adding an image volume to a pod
To mount an Open Container Initiative (OCI)-compliant container image, use the volume parameter to include a path to the image in your pod spec with an optional pull policy. You can create the pod directly or use a controlling object, such as a deployment or replica set.
Procedure
Create a YAML file similar to the following.
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:1 reference: quay.io/crio/image:v22 pullPolicy: Always3 - 1
- Specifies an OCI container image that is available on the host machine.
- 2
- Specifies the path to the image.
- 3
- Specifies a pull policy, one of the following options:
-
If
Always, the kubelet always attempts to pull the image. If the pull fails, the kubelet sets the pod toFailed. -
If
Never, the kubelet never pulls the image and only uses a local image. The pod becomesFailedif any layers of the image are not present locally, or if the manifest for that image is not already cached. -
If
IfNotPresentthe kubelet pulls the image if it is not present. The pod becomesFailedif the image is not present and the pull fails. This is the default.
-
If
Create the pod by running the following command:
$ oc create -f <file_name>.yaml
Verification
Examine the pod to view detailed information about the image pull and mount by using a command similar to the following:
$ oc describe pod <pod_name>Example output
Name: image-volume Namespace: default # ... Volumes: volume:1 Type: Image Reference: quay.io/crio/image:v2 PullPolicy: IfNotPresent # ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- # ... Normal Pulling 46s kubelet Pulling image "quay.io/crio/image:v2" Normal Pulled 44s kubelet Successfully pulled image "quay.io/crio/image:v2" in 2.261s (2.261s including waiting). Image size: 6707 bytes.2 # ...