configMap 如何映射文件到已存在目录呢

289 天前
 wtfedc

比如我有个目录/dir ,里边已经有文件 a.txt,b.txt 。 想用 configMap 把 c.txt,d.txt ,也映射到/dir ,但是不覆盖掉 a.txt,b.txt 。

我尝试了把 c.txt,d.txt 放到一个 configMap 中,映射到/dir 时,发现只有 c.txt,d.txt ,其他文件都丢失了。 又尝试了分开放在两个 configMap 中,分别映射到/dir/c.txt,/dir/d.txt ,结果 c.txt ,d.txt 成了目录格式。

402 次点击
所在节点    问与答
3 条回复
fengxsong
289 天前
configured with `subPath`
wtfedc
289 天前
@fengxsong chatGPT 给了这个响应,但是前后矛盾。它后边的回答是这样:
```
Apologies for the confusion. You are right; using the subPath field in the volumeMounts will override the entire directory in the container with the contents of the ConfigMap, which is not the behavior we want.
```
wtfedc
289 天前
最终用 subPath 搞定了,chatGPT3.5 给的答案不靠谱。
参考了这篇文章: https://dev.to/joshduffney/kubernetes-using-configmap-subpaths-to-mount-files-3a1i

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/960142

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX