DEV Community

Discussion on: Kubernetes - Using ConfigMap SubPaths to Mount Files

Collapse
 
thoki123 profile image
thoki123

I tried your steps with OpenShift v4.19 (Kubernetes 1.19) and it didn't work. The directory (which is a Tomcat 9 deployment) is still overwritten by the single file (logback.xml) in the volume

kind: ConfigMap
apiVersion: v1
metadata:
  name: logback-configmap
data:
  logback: |
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="60 seconds">
[...]
Enter fullscreen mode Exit fullscreen mode

and in the deployment config:

[...]
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
[..]
Enter fullscreen mode Exit fullscreen mode
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
Enter fullscreen mode Exit fullscreen mode

Do you have any idea why this is not working?