Skip to content

Commit 77cb162

Browse files
committed
[zh] Add a task: image-volumes.md and its dependent files
1 parent 493c8db commit 77cb162

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
14+
<!--
15+
Allow using the [`image`](/docs/concepts/storage/volumes/) volume source in a Pod.
16+
This volume source lets you mount a container image as a read-only volume.
17+
-->
18+
允许在 Pod 中使用 [`image`](/zh-cn/docs/concepts/storage/volumes/) 卷源。
19+
这个卷源允许你将容器镜像挂载为只读卷。
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: Pod 使用镜像卷
3+
reviewers:
4+
content_type: task
5+
weight: 210
6+
min-kubernetes-server-version: v1.31
7+
---
8+
<!--
9+
title: Use an Image Volume With a Pod
10+
reviewers:
11+
content_type: task
12+
weight: 210
13+
min-kubernetes-server-version: v1.31
14+
-->
15+
16+
<!-- overview -->
17+
18+
{{< feature-state feature_gate_name="ImageVolume" >}}
19+
20+
<!--
21+
This page shows how to configure a pod using image volumes. This allows you to
22+
mount content from OCI registries inside containers.
23+
-->
24+
本页展示了如何使用镜像卷配置 Pod。此特性允许你在容器内挂载来自 OCI 镜像仓库的内容。
25+
26+
## {{% heading "prerequisites" %}}
27+
28+
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
29+
30+
<!--
31+
- The container runtime needs to support the image volumes feature
32+
- You need to exec commands in the host
33+
- You need to be able to exec into pods
34+
- You need to enable the `ImageVolume` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
35+
-->
36+
- 容器运行时需要支持镜像卷特性
37+
- 你需要能够在主机上执行命令
38+
- 你需要能够进入 Pod 执行命令
39+
- 你需要启用 `ImageVolume`
40+
[特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/)
41+
42+
<!-- steps -->
43+
44+
<!--
45+
## Run a Pod that uses an image volume {#create-pod}
46+
47+
An image volume for a pod is enabled setting the `volumes.[*].image` field of `.spec`
48+
to a valid reference and consuming it in the `volumeMounts` of the container. For example:
49+
-->
50+
## 运行使用镜像卷的 Pod {#create-pod}
51+
52+
为 Pod 启用镜像卷的方式是:在 `.spec` 中将 `volumes.[*].image`
53+
字段设置为一个有效的镜像并在容器的 `volumeMounts` 中消费此镜像。例如:
54+
55+
{{% code_sample file="pods/image-volumes.yaml" %}}
56+
57+
<!--
58+
1. Create the pod on your cluster:
59+
-->
60+
1. 在你的集群上创建 Pod:
61+
62+
```shell
63+
kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml
64+
```
65+
66+
<!--
67+
1. Attach to the container:
68+
-->
69+
2. 挂接到容器:
70+
71+
```shell
72+
kubectl attach -it image-volume bash
73+
```
74+
75+
<!--
76+
1. Check the content of a file in the volume:
77+
-->
78+
3. 查看卷中某个文件的内容:
79+
80+
```shell
81+
cat /volume/dir/file
82+
```
83+
84+
<!--
85+
The output is similar to:
86+
-->
87+
输出类似于:
88+
89+
```none
90+
1
91+
```
92+
93+
<!--
94+
You can also check another file in a different path:
95+
-->
96+
你还可以查看不同路径中的另一个文件:
97+
98+
```shell
99+
cat /volume/file
100+
```
101+
102+
<!--
103+
The output is similar to:
104+
-->
105+
输出类似于:
106+
107+
```none
108+
2
109+
```
110+
111+
<!--
112+
## Further reading
113+
114+
- [`image` volumes](/docs/concepts/storage/volumes/#image)
115+
-->
116+
## 进一步阅读
117+
118+
- [`image`](/zh-cn/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)