From 77cb162195744d3b357f7ab5936a45a187789118 Mon Sep 17 00:00:00 2001 From: windsonsea Date: Thu, 22 Aug 2024 17:34:28 +0800 Subject: [PATCH] [zh] Add a task: image-volumes.md and its dependent files --- .../feature-gates/image-volume.md | 19 +++ .../configure-pod-container/image-volumes.md | 118 ++++++++++++++++++ .../zh-cn/examples/pods/image-volumes.yaml | 17 +++ 3 files changed, 154 insertions(+) create mode 100644 content/zh-cn/docs/reference/command-line-tools-reference/feature-gates/image-volume.md create mode 100644 content/zh-cn/docs/tasks/configure-pod-container/image-volumes.md create mode 100644 content/zh-cn/examples/pods/image-volumes.yaml diff --git a/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates/image-volume.md b/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates/image-volume.md new file mode 100644 index 0000000000..2fdafa317a --- /dev/null +++ b/content/zh-cn/docs/reference/command-line-tools-reference/feature-gates/image-volume.md @@ -0,0 +1,19 @@ +--- +title: ImageVolume +content_type: feature_gate +_build: + list: never + render: false + +stages: + - stage: alpha + defaultValue: false + fromVersion: "1.31" +--- + + +允许在 Pod 中使用 [`image`](/zh-cn/docs/concepts/storage/volumes/) 卷源。 +这个卷源允许你将容器镜像挂载为只读卷。 diff --git a/content/zh-cn/docs/tasks/configure-pod-container/image-volumes.md b/content/zh-cn/docs/tasks/configure-pod-container/image-volumes.md new file mode 100644 index 0000000000..fb396c8fd3 --- /dev/null +++ b/content/zh-cn/docs/tasks/configure-pod-container/image-volumes.md @@ -0,0 +1,118 @@ +--- +title: Pod 使用镜像卷 +reviewers: +content_type: task +weight: 210 +min-kubernetes-server-version: v1.31 +--- + + + + +{{< feature-state feature_gate_name="ImageVolume" >}} + + +本页展示了如何使用镜像卷配置 Pod。此特性允许你在容器内挂载来自 OCI 镜像仓库的内容。 + +## {{% heading "prerequisites" %}} + +{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} + + +- 容器运行时需要支持镜像卷特性 +- 你需要能够在主机上执行命令 +- 你需要能够进入 Pod 执行命令 +- 你需要启用 `ImageVolume` + [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/) + + + + +## 运行使用镜像卷的 Pod {#create-pod} + +为 Pod 启用镜像卷的方式是:在 `.spec` 中将 `volumes.[*].image` +字段设置为一个有效的镜像并在容器的 `volumeMounts` 中消费此镜像。例如: + +{{% code_sample file="pods/image-volumes.yaml" %}} + + +1. 在你的集群上创建 Pod: + + ```shell + kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml + ``` + + +2. 挂接到容器: + + ```shell + kubectl attach -it image-volume bash + ``` + + +3. 查看卷中某个文件的内容: + + ```shell + cat /volume/dir/file + ``` + + + 输出类似于: + + ```none + 1 + ``` + + + 你还可以查看不同路径中的另一个文件: + + ```shell + cat /volume/file + ``` + + + 输出类似于: + + ```none + 2 + ``` + + +## 进一步阅读 + +- [`image` 卷](/zh-cn/docs/concepts/storage/volumes/#image) diff --git a/content/zh-cn/examples/pods/image-volumes.yaml b/content/zh-cn/examples/pods/image-volumes.yaml new file mode 100644 index 0000000000..3a3cc79a4a --- /dev/null +++ b/content/zh-cn/examples/pods/image-volumes.yaml @@ -0,0 +1,17 @@ +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: + reference: quay.io/crio/artifact:v1 + pullPolicy: IfNotPresent