V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wtfedc
V2EX  ›  问与答

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

  •  
  •   wtfedc · 276 天前 · 383 次点击
    这是一个创建于 276 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如我有个目录/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 成了目录格式。

    3 条回复    2023-07-27 16:28:31 +08:00
    fengxsong
        1
    fengxsong  
       276 天前
    configured with `subPath`
    wtfedc
        2
    wtfedc  
    OP
       276 天前
    @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
        3
    wtfedc  
    OP
       275 天前
    最终用 subPath 搞定了,chatGPT3.5 给的答案不靠谱。
    参考了这篇文章: https://dev.to/joshduffney/kubernetes-using-configmap-subpaths-to-mount-files-3a1i
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4827 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:59 · PVG 11:59 · LAX 20:59 · JFK 23:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.