<p>The pod yaml</p>
<pre><code>      containers:
        - name: kiada
          image: :kiada-0.1
          volumeMounts:
            - name: my-test
              subPath: my-app.conf
              mountPath: /html/my-app.conf
           
      volumes:
        - name: my-test
          configMap:
            name: kiada-config

</code></pre>
<p>the config map</p>
<pre><code>➜  v5-kubernetes git:(master) ✗ k get cm kiada-config -oyaml
apiVersion: v1
data:
  key: value\n
  status-message: This status message is set in the kiada-config config map2\n
kind: ConfigMap
metadata:
  creationTimestamp: &quot;2022-05-18T03:01:15Z&quot;
  name: kiada-config
  namespace: default
  resourceVersion: &quot;135185128&quot;
  uid: 8c8875ce-47f5-49d4-8bc7-d8dbc2d7f7ba
</code></pre>
<p>the pod  has my-app.conf</p>
<pre><code>root@kiada2-7cc7bf55d8-m97tt:/# ls -al /html/my-app.conf/
total 12
drwxrwxrwx 3 root root 4096 May 21 02:29 .
drwxr-xr-x 1 root root 4096 May 21 02:29 ..
drwxr-xr-x 2 root root 4096 May 21 02:29 ..2022_05_21_02_29_41.554311630
lrwxrwxrwx 1 root root   31 May 21 02:29 ..data -&gt; ..2022_05_21_02_29_41.554311630
lrwxrwxrwx 1 root root   10 May 21 02:29 key -&gt; ..data/key
lrwxrwxrwx 1 root root   21 May 21 02:29 status-message -&gt; ..data/status-message
root@kiada2-7cc7bf55d8-m97tt:/# ls -al /html/my-app.conf/
</code></pre>
<p>if i add subPath in pod yaml</p>
<pre><code>spec:
      containers:
        - name: kiada
          image: kiada-0.1
          volumeMounts:
            - name: my-test
              subPath: my-app.conf
              mountPath: /html/my-app.conf
           
      volumes:
        - name: my-test
          configMap:
            name: kiada-config
</code></pre>
<p>the resutl</p>
<pre><code>root@kiada2-c89749c8-x9qwq:/# ls -al html/my-app.conf/
total 8
drwxrwxrwx 2 root root 4096 May 21 02:36 .
drwxr-xr-x 1 root root 4096 May 21 02:36 ..
</code></pre>
<p>why i use subPath,the config map key is not exists ,what's wrong?</p>

fuyou001
<p>In order to produce a file called <code>my-app.config</code> containing your application config in your Pod's file system, would have to ensure that this file <strong>exists in your config map</strong>:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: kiada-config
data:
  my-app.conf: |
    key: value
    status-message: This status message is set in the kiada-config config map2
</code></pre>
<p>Then, you can mount it into your Pod like this:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    run: kiada
  name: kiada
spec:
  containers:
    - name: kiada
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;tail -f /dev/null&quot; ]
      volumeMounts:
        - mountPath: /html/
          name: my-test
  volumes:
    - name: my-test
      configMap:
        name: kiada-config
</code></pre>
<p>The <em>subPath</em> field is not required in this scenario. It would be useful <strong>either</strong> if you want to remap the <code>my-app.conf</code> to a different name..</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    run: kiada
  name: kiada
spec:
  containers:
    - name: kiada
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;tail -f /dev/null&quot; ]
      volumeMounts:
        - mountPath: /html/my-app-new-name.conf
          name: my-test
          subPath: my-app.conf
  volumes:
    - name: my-test
      configMap:
        name: kiada-config
</code></pre>
<p>..<strong>or</strong>, if you had multiple config files in your ConfigMap and just wanted to map one of them into your Pod:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: kiada-config
data:
  my-app.conf: |
    key: value
    status-message: This status message is set in the kiada-config config map2
  my-second-app.conf: |
    error: not in use
</code></pre>
<hr />
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    run: kiada
  name: kiada
spec:
  containers:
    - name: kiada
      image: k8s.gcr.io/busybox
      command: [ &quot;/bin/sh&quot;, &quot;-c&quot;, &quot;tail -f /dev/null&quot; ]
      volumeMounts:
        - mountPath: /html/my-app.conf
          name: my-test
          subPath: my-app.conf
  volumes:
    - name: my-test
      configMap:
        name: kiada-config
</code></pre>
