What's the best way to share/mount one file into a pod?

Smana picture Smana · Oct 29, 2015 · Viewed 69.5k times · Source

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?

Answer

Tommy Nguyen picture Tommy Nguyen · Apr 14, 2017

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

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

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"
---

Full example here