<p>I have a Spring Boot app deployed under a Tomcat server inside a POD with Openshift 4.19 (which uses Kubernetes 1.19). My goal is to externalize the logback configuration to a configmap, so that I can change the loglevel as needed in production without restarting the pods.</p>
<p>I used the following configuration:</p>
<p><strong>ConfigMap</strong></p>
<pre><code>    kind: ConfigMap
apiVersion: v1
metadata:
  name: logback-configmap
[..]
data:
  logback: |
    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;configuration scan=&quot;true&quot; scanPeriod=&quot;60 seconds&quot;&gt;
[...]
</code></pre>
<p><strong>Deployment Config</strong></p>
<pre><code>[...]
spec:
      volumes:
        - name: logback-configmap-volume
          configMap:
            name: logback-configmap
            items:
              - key: logback
                path: logback.xml
            defaultMode: 420
[..]
         volumeMounts:
            - name: logback-configmap-volume
              mountPath: /deployments/zfaRouter/WEB-INF/classes/logback.xml
              subPath: logback.xml
[..]
</code></pre>
<p>The problem is, that the above config clears the complete directory structure under /deployments/zfaRouter/WEB-INF/classes/:</p>
<pre><code>sh-4.4$ ls -la /deployments/zfaRouter/WEB-INF/classes/
total 4
drwxr-xr-x. 2 root root         25 May  4 16:35 .
drwxr-xr-x. 3 root root         21 May  4 16:35 ..
-rw-r--r--. 1 root 1015170000 1084 May  4 16:35 logback.xml
</code></pre>
<p>I tried every possible combination (eg. without subPath element, without the filename in the mountPath, without the items element in the volumes section) without any luck. From what a read here and in the official Kubernetes docs, it should work like the configuration above.</p>
<p>Any ideas on this problem?</p>

Thorsten Kitz
<p>The directory that is used as mount point shadows all other content, therefore it appears like overwriting what you expect to be there. Even if you want to 'just' have a single file mounted, a mount point must exist.</p>
<p>For your specific scenario you could either mount to a different directory, like <code>/config</code> and add it to the classpath, or you can use a subdirectory like <code>/deployments/zfaRouter/WEB-INF/classes/config</code> and add that to the classpath.</p>
<p>If you don't want to change the classpath you could mount the config file to, f.e. <code>/config</code> and change your application start script to copy it to a fitting location, for example to the tomcat shared lib folder that is picked up by the tomcat classloader.</p>
