|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * nodes/pods/nodes-pods-image-volume.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="nodes-pods-image-volume-adding_{context}"] |
| 7 | += Adding an image volume to a pod |
| 8 | + |
| 9 | +To mount an Open Container Initiative (OCI)-compliant container image or artifact, use the `volume` parameter to include a path to the image or artifact 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. |
| 10 | + |
| 11 | +.Procedure |
| 12 | + |
| 13 | +. Create a YAML file similar to the following. |
| 14 | ++ |
| 15 | +[source,yaml] |
| 16 | +---- |
| 17 | +apiVersion: v1 |
| 18 | +kind: Pod |
| 19 | +metadata: |
| 20 | + name: image-volume |
| 21 | +spec: |
| 22 | + containers: |
| 23 | + - name: shell |
| 24 | + command: ["sleep", "infinity"] |
| 25 | + image: debian |
| 26 | + volumeMounts: |
| 27 | + - name: volume |
| 28 | + mountPath: /volume |
| 29 | + volumes: |
| 30 | + - name: volume |
| 31 | + image: <1> |
| 32 | + reference: quay.io/crio/artifact:v2 <2> |
| 33 | + pullPolicy: Always <3> |
| 34 | +---- |
| 35 | +<1> Specifies an OCI container image or artifact that is available on the host machine. |
| 36 | +<2> Specifies the path to the image or artifact. |
| 37 | +<3> Specifies a pull policy, one of the following options: |
| 38 | ++ |
| 39 | +-- |
| 40 | +* If `Always`, the kubelet always attempts to pull the image. If the pull fails, the kubelet sets the pod to `Failed`. |
| 41 | +* If `Never`, the kubelet never pulls the image and only uses a local image or artifact. The pod becomes `Failed` if any layers of the image are not present locally, or if the manifest for that image is not already cached. |
| 42 | +* If `IfNotPresent` the kubelet pulls the image if it not present. The pod becomes `Failed` if the image is not present and the pull fails. This is the default. |
| 43 | +-- |
| 44 | +// Pull policy details from upstream: https://kubernetes.io/docs/concepts/storage/volumes/#image |
| 45 | + |
| 46 | +. Create the pod by running the following command: |
| 47 | ++ |
| 48 | +[source,terminal] |
| 49 | +---- |
| 50 | +$ oc create -f <file_name>.yaml |
| 51 | +---- |
| 52 | + |
| 53 | +.Verification |
| 54 | + |
| 55 | +* Examine the pod to view detailed information about the image pull and mount by using a command similar to the following: |
| 56 | ++ |
| 57 | +[source,terminal] |
| 58 | +---- |
| 59 | +$ oc describe pod <pod_name> |
| 60 | +---- |
| 61 | ++ |
| 62 | +.Example output |
| 63 | +[source,yaml] |
| 64 | +---- |
| 65 | +Name: image-volume |
| 66 | +Namespace: default |
| 67 | +# ... |
| 68 | +Volumes: |
| 69 | + volume: <1> |
| 70 | + Type: Image (a container image or OCI artifact) |
| 71 | + Reference: quay.io/crio/artifact:v2 |
| 72 | + PullPolicy: IfNotPresent |
| 73 | +# ... |
| 74 | +Events: |
| 75 | + Type Reason Age From Message |
| 76 | + ---- ------ ---- ---- ------- |
| 77 | +# ... |
| 78 | + Normal Pulling 46s kubelet Pulling image "quay.io/crio/artifact:v2" |
| 79 | + Normal Pulled 44s kubelet Successfully pulled image "quay.io/crio/artifact:v2" in 2.261s (2.261s including waiting). Image size: 6707 bytes. <2> |
| 80 | +# ... |
| 81 | +---- |
| 82 | +<1> Indicates that the image volume was mounted to the pod. |
| 83 | +<2> Indicates that the image was successfully pulled. |
0 commit comments