Skip to content

Commit 4969c23

Browse files
committed
Add ImageVolume documentation
Add a basic task how to use image volumes in pods. Signed-off-by: Sascha Grunert <[email protected]>
1 parent be3a417 commit 4969c23

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

content/en/docs/concepts/storage/volumes.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,72 @@ spec:
534534
type: FileOrCreate
535535
```
536536

537+
### image
538+
539+
{{< feature-state feature_gate_name="ImageVolume" >}}
540+
541+
An `image` volume source represents an OCI object (a container image or
542+
artifact) which is available on the kubelet's host machine.
543+
544+
One example to use the `image` volume source is:
545+
546+
{{% code_sample file="pods/image-volumes.yaml" %}}
547+
548+
The volume is resolved at pod startup depending on which `pullPolicy` value is
549+
provided:
550+
551+
`Always`
552+
: the kubelet always attempts to pull the reference. If the pull fails, the kubelet sets the Pod to `Failed`.
553+
554+
`Never`
555+
: the kubelet never pulls the reference and only uses a local image or artifact. The Pod becomes `Failed` if any layers of the image aren't already present locally, or if the manifest for that image isn't already cached.
556+
557+
`IfNotPresent`
558+
: the kubelet pulls if the reference isn't already present on disk. The Pod becomes `Failed` if the reference isn't present and the pull fails.
559+
560+
The volume gets re-resolved if the pod gets deleted and recreated, which means
561+
that new remote content will become available on pod recreation. A failure to
562+
resolve or pull the image during pod startup will block containers from starting
563+
and may add significant latency. Failures will be retried using normal volume
564+
backoff and will be reported on the pod reason and message.
565+
566+
The types of objects that may be mounted by this volume are defined by the
567+
container runtime implementation on a host machine and at minimum must include
568+
all valid types supported by the container image field. The OCI object gets
569+
mounted in a single directory (`spec.containers[*].volumeMounts.mountPath`) by
570+
will be mounted read-only. On Linux, the container runtime typically also mounts the
571+
volume with file execution blocked (`noexec`).
572+
573+
Beside that:
574+
- Sub path mounts for containers are not supported
575+
(`spec.containers[*].volumeMounts.subpath`).
576+
- The field `spec.securityContext.fsGroupChangePolicy` has no effect on this
577+
volume type.
578+
- The [`AlwaysPullImages` Admission Controller](/docs/reference/access-authn-authz/admission-controllers/#alwayspullimages)
579+
does also work for this volume source like for container images.
580+
581+
The following fields are available for the `image` type:
582+
583+
`reference`
584+
: Artifact reference to be used. For example, you could specify
585+
`registry.k8s.io/conformance:v${{< skew currentPatchVersion >}}` to load the
586+
files from the Kubernetes conformance test image. Behaves in the same way as
587+
`pod.spec.containers[*].image`. Pull secrets will be assembled in the same way
588+
as for the container image by looking up node credentials, service account image
589+
pull secrets, and pod spec image pull secrets. This field is optional to allow
590+
higher level config management to default or override container images in
591+
workload controllers like Deployments and StatefulSets.
592+
593+
[More info about container images](/docs/concepts/containers/images)
594+
595+
`pullPolicy`
596+
: Policy for pulling OCI objects. Possible values are: `Always`, `Never` or
597+
`IfNotPresent`. Defaults to `Always` if `:latest` tag is specified, or
598+
`IfNotPresent` otherwise.
599+
600+
See the [_Use an Image Volume With a Pod_](/docs/tasks/configure-pod-container/image-volumes)
601+
example for more details on how to use the volume source.
602+
537603
### iscsi
538604

539605
An `iscsi` volume allows an existing iSCSI (SCSI over IP) volume to be mounted
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: ImageVolume
3+
content_type: feature_gate
4+
_build:
5+
list: never
6+
render: false
7+
8+
stages:
9+
- stage: alpha
10+
defaultValue: false
11+
fromVersion: "1.31"
12+
---
13+
Allow using the [`image`](/docs/concepts/storage/volumes/) volume source in a Pod.
14+
This volume source lets you mount a container image as a read-only volume.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Use an Image Volume With a Pod
3+
reviewers:
4+
content_type: task
5+
weight: 210
6+
min-kubernetes-server-version: v1.31
7+
---
8+
9+
<!-- overview -->
10+
11+
{{< feature-state feature_gate_name="ImageVolume" >}}
12+
13+
This page shows how to configure a pod using image volumes. This allows you to
14+
mount content from OCI registries inside containers.
15+
16+
## {{% heading "prerequisites" %}}
17+
18+
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
19+
20+
- The container runtime needs to support the image volumes feature
21+
- You need to exec commands in the host
22+
- You need to be able to exec into pods
23+
- You need to enable the `ImageVolume` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
24+
25+
<!-- steps -->
26+
27+
## Run a Pod that uses an image volume {#create-pod}
28+
29+
An image volume for a pod is enabled setting the `volumes.[*].image` field of `.spec`
30+
to a valid reference and consuming it in the `volumeMounts` of the container. For example:
31+
32+
{{% code_sample file="pods/image-volumes.yaml" %}}
33+
34+
1. Create the pod on your cluster:
35+
36+
```shell
37+
kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml
38+
```
39+
40+
1. Attach to the container:
41+
42+
```shell
43+
kubectl attach -it image-volume bash
44+
```
45+
46+
Run this command:
47+
48+
```shell
49+
cat /volume/dir/file
50+
```
51+
52+
The output is similar to:
53+
54+
```shell
55+
1
56+
```
57+
58+
Also run:
59+
60+
```shell
61+
cat /volume/file
62+
```
63+
64+
The output is similar to:
65+
66+
```shell
67+
2
68+
```
69+
70+
## Further reading
71+
72+
- [`image` volumes](/docs/concepts/storage/volumes/#image)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: image-volume
5+
spec:
6+
containers:
7+
- name: shell
8+
command: ["sleep", "infinity"]
9+
image: debian
10+
volumeMounts:
11+
- name: volume
12+
mountPath: /volume
13+
volumes:
14+
- name: volume
15+
image:
16+
reference: quay.io/crio/artifact:v1
17+
pullPolicy: IfNotPresent

0 commit comments

Comments
 (0)