将一个文件共享/挂载到 pod 中的最佳方法是什么? [英] What's the best way to share/mount one file into a pod?

查看:46
本文介绍了将一个文件共享/挂载到 pod 中的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用秘密来挂载单个文件,但似乎您只能挂载会覆盖所有其他内容的目录.如何在不挂载目录的情况下共享单个配置文件?

I was considering using secrets to mount a single file but it seems that you can only mount directory that will overwrites all the other content. How can I share a single config file without mounting a directory?

推荐答案

例如,您有一个包含 2 个配置文件的 configmap:

For example you have a configmap which contain 2 config files:

kubectl create configmap config --from-file <file1> --from-file <file2>

您可以像这样使用 subPath 将单个文件挂载到现有目录中:

You could use subPath like this to mount single file into existing directory:

---
        volumeMounts:
        - name: "config"
          mountPath: "/<existing folder>/<file1>"
          subPath: "<file1>"
        - name: "config"
          mountPath: "/<existing folder>/<file2>"
          subPath: "<file2>"
      restartPolicy: Always
      volumes:
        - name: "config"
          configMap:
            name: "config"
---

完整示例此处

这篇关于将一个文件共享/挂载到 pod 中的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆