<p>Now I read this config in kubernetes:</p>
<pre><code> containers:
        - name: canal-admin-stable
          image: 'dolphinjiang/canal-admin:v1.1.5'
          ports:
            - name: http
              containerPort: 8089
              protocol: TCP
          resources:
            limits:
              cpu: '2'
              memory: 2Gi
            requests:
              cpu: 100m
              memory: 100Mi
          volumeMounts:
            - name: admin-conf
              mountPath: /home/canal/conf/application.yml
              subPath: application.yml
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
</code></pre>
<p>the volumne mount path(<code>/home/canal/conf/application.yml</code>) already file full path, I think kubernetes only overwrite the file application.yml, why still specify subPath <code>application.yml</code>? Why not write like this:</p>
<pre><code>volumeMounts:
     - name: admin-conf
       mountPath: /home/canal/conf/
       subPath: application.yml
</code></pre>

Dolphin
<p>I was using init-containers to pass a config file to the main container and discovered the use behind the mountPath and subPath as it was confusing to me too at first. The mountPath is always the destination inside the Pod a volume gets mounted to. However, I discovered that if your mountPath has other config files in it, then that directory will be overwritten and all that exists will be your file that you mounted.</p>
<p>I only needed to mount part of the volume, such as a single file in a volume, so I  used subPath to specify the part to be mounted within the mountPath.</p>
<p>Sometimes using just a mountPath is fine, but I had to also use a subPath to preserve the other config files in the directory.</p>
