我正在尝试将 volumeMounts 中的文件添加到 .dockerignore 并试图了解 subPath 和 mountPath 之间的区别。阅读官方文档对我来说不是很清楚。
我应该从我读取的内容中添加 mountPath 是 pod 中将安装卷的目录。
来自官方文档:“subPath volumeMounts.subPath 属性指定引用卷内的子路径而不是其根。” https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath(这部分不清楚)
- mountPath: /root/test.pem
name: test-private-key
subPath: test.testing.com.key
在这个例子中,我应该将 test.pem 和 test.testing.com.key 都包含到 dockerignore 中吗?
答案 0 :(得分:13)
mountPath
显示引用卷应安装在容器中的位置。例如,如果您将卷挂载到 mountPath: /a/b/c
,则该卷将可供目录 /a/b/c
下的容器使用。
安装卷将使所有卷在 mountPath
下可用。如果您只需要挂载卷的一部分,例如卷中的单个文件,您可以使用 subPath
指定必须挂载的部分。例如,mountPath: /a/b/c
、subPath: d
将生成目录 d
/a/b/c