<p>In my deployment, I would like to use a Persistent Volume Claim in combination with a config map mount. For example, I'd like the following:</p>

<pre><code>volumeMounts:
    - name: py-js-storage
        mountPath: /home/python
    - name: my-config
        mountPath: /home/python/my-config.properties
        subPath: my-config.properties
        readOnly: true
...
    volumes:
    - name: py-storage
    {{- if .Values.py.persistence.enabled }}
        persistentVolumeClaim:
        claimName: python-storage
    {{- else }}
        emptyDir: {}
    {{- end }}
</code></pre>

<p>Is this a possible and viable way to go? Is there any better way to approach such situation? </p>

<p>Since you didn't give your use case, my answer will be based on if it is possible or not. In fact: <strong>Yes, it is.</strong></p>

<p>I'm supposing you wish mount file from a <code>configMap</code> in a mount point that already contains other files, and your approach to use <code>subPath</code> is correct!</p>

<p>When you need to mount different volumes on the same path, you need specify <code>subPath</code> or the content of the original dir will be <strong>hidden</strong>.</p>

<p>In other words, if you want to keep both files (from the mount point <strong>and</strong> from configMap) you <strong>must</strong> use <code>subPath</code>.</p>

<p>To illustrate this, I've tested with the deployment code below. There I mount the hostPath <code>/mnt</code> that contains a file called <code>filesystem-file.txt</code> in my pod and the file <code>/mnt/configmap-file.txt</code> from my configmap <code>test-pd-plus-cfgmap</code>:</p>

<blockquote>
  <p><strong>Note:</strong> I'm using Kubernetes 1.18.1</p>
</blockquote>

<p><strong>Configmap:</strong></p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: test-pd-plus-cfgmap
data:
  file-from-cfgmap: file data
</code></pre>

<p><strong>Deployment:</strong></p>

<pre><code>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-pv
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-pv
  template:
    metadata:
      labels:
        app: test-pv
    spec:
      containers:
      - image: nginx
        name: nginx
        volumeMounts:
        - mountPath: /mnt
          name: task-pv-storage
        - mountPath: /mnt/configmap-file.txt
          subPath: configmap-file.txt
          name: task-cm-file
      volumes:
        - name: task-pv-storage
          persistentVolumeClaim:
            claimName: task-pv-claim
        - name: task-cm-file
          configMap:
            name: test-pd-plus-cfgmap
</code></pre>

<p>As a result of the deployment, you can see the follow content in <code>/mnt</code> of the pod:</p>

<pre><code>$ kubectl exec test-pv-5bcb54bd46-q2xwm -- ls /mnt
configmap-file.txt
filesystem-file.txt
</code></pre>

<p>You could check this github <a href="https://github.com/kubernetes/kubernetes/issues/23748" rel="noreferrer">issue</a> with the same discussion.</p>

<p><a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="noreferrer">Here</a> you could read a little more about volumes <code>subPath</code>.</p>
