mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
121 lines
4.2 KiB
Plaintext
121 lines
4.2 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * nodes/pods/nodes-pods-image-volume.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="nodes-pods-image-volume-adding_{context}"]
|
|
= Adding an image volume to a pod
|
|
|
|
//Hiding artifacts in 4.20; artifacts to go TP in 4.21
|
|
////
|
|
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.
|
|
////
|
|
|
|
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.
|
|
+
|
|
[source,yaml]
|
|
----
|
|
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:v2 <2>
|
|
pullPolicy: Always <3>
|
|
----
|
|
<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 to `Failed`.
|
|
* If `Never`, the kubelet never pulls the image and only uses a local image. 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.
|
|
* If `IfNotPresent` the kubelet pulls the image if it is not present. The pod becomes `Failed` if the image is not present and the pull fails. This is the default.
|
|
// Pull policy details from upstream: https://kubernetes.io/docs/concepts/storage/volumes/#image
|
|
|
|
. Create the pod by running the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <file_name>.yaml
|
|
----
|
|
|
|
////
|
|
. Create a YAML file similar to the following.
|
|
+
|
|
[source,yaml]
|
|
----
|
|
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:v2 <2>
|
|
pullPolicy: Always <3>
|
|
----
|
|
<1> Specifies an OCI container image or artifact that is available on the host machine.
|
|
<2> Specifies the path to the image or artifact.
|
|
<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 to `Failed`.
|
|
* 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.
|
|
* If `IfNotPresent` the kubelet pulls the image if it is not present. The pod becomes `Failed` if the image is not present and the pull fails. This is the default.
|
|
--
|
|
// Pull policy details from upstream: https://kubernetes.io/docs/concepts/storage/volumes/#image
|
|
////
|
|
|
|
.Verification
|
|
|
|
* Examine the pod to view detailed information about the image pull and mount by using a command similar to the following:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc describe pod <pod_name>
|
|
----
|
|
+
|
|
.Example output
|
|
[source,yaml]
|
|
----
|
|
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>
|
|
# ...
|
|
----
|
|
<1> Indicates that the image was mounted to the pod.
|
|
<2> Indicates that the image was successfully pulled.
|