Skip to content

Commit a6ac726

Browse files
authored
Merge pull request #46946 from saschagrunert/oci-volumesource-docs
Document OCI volume sources / KEP-4639
2 parents 01a668b + a12454f commit a6ac726

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,71 @@ spec:
543543
type: FileOrCreate
544544
```
545545

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

548613
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)