2.6 KiB
2.6 KiB
title | reviewers | content_type | weight | min-kubernetes-server-version |
---|---|---|---|---|
Pod 使用镜像卷 | task | 210 | v1.31 |
{{< feature-state feature_gate_name="ImageVolume" >}}
本页展示了如何使用镜像卷配置 Pod。此特性允许你在容器内挂载来自 OCI 镜像仓库的内容。
{{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
- 容器运行时需要支持镜像卷特性
- 你需要能够在主机上执行命令
- 你需要能够进入 Pod 执行命令
- 你需要启用
ImageVolume
特性门控
运行使用镜像卷的 Pod
为 Pod 启用镜像卷的方式是:在 .spec
中将 volumes.[*].image
字段设置为一个有效的镜像并在容器的 volumeMounts
中消费此镜像。例如:
{{% code_sample file="pods/image-volumes.yaml" %}}
-
在你的集群上创建 Pod:
kubectl apply -f https://k8s.io/examples/pods/image-volumes.yaml
-
挂接到容器:
kubectl attach -it image-volume bash
-
查看卷中某个文件的内容:
cat /volume/dir/file
输出类似于:
1
你还可以查看不同路径中的另一个文件:
cat /volume/file
输出类似于:
2