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

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


I'd start with this working example from here. Make sure you're using at least Kubernetes 1.3.

Simply create a ConfigMap like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: test-pd-plus-cfgmap
data:
  file-from-cfgmap: file data

And then create a pod like this:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd-plus-cfgmap
spec:
  containers:
  - image: ubuntu
    name: bash
    stdin: true
    stdinOnce: true
    tty: true
    volumeMounts:
    - mountPath: /mnt
      name: pd
    - mountPath: /mnt/file-from-cfgmap
      name: cfgmap
      subPath: file-from-cfgmap
  volumes:
  - name: pd
    gcePersistentDisk:
      pdName: testdisk
  - name: cfgmap
    configMap:
      name: test-pd-plus-cfgmap