<p>I am working on Springboot and Kubernetes and I have really simple application that connects to Postgres database. I want to get the value of datasource from configmap and password from secrets as mount file.</p>
<p>Configmap file :</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: customer-config
data:
  application.properties: |
    server.forward-headers-strategy=framework
    spring.datasource.url=jdbc:postgresql://test/customer
    spring.datasource.username=postgres
</code></pre>
<p>Secrets File :</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: secret-demo
data:
  spring.datasource.password: cG9zdGdyZXM=
</code></pre>
<p>deployment file :</p>
<pre><code>spec:
  containers:
    - name: customerc
      image: localhost:8080/customer
      imagePullPolicy: IfNotPresent
      ports:
        - containerPort: 8282
      volumeMounts:
        - mountPath: /workspace/config/default
          name: config-volume
        - mountPath: /workspace/secret/default
          name: secret-volume
  volumes:
    - name: config-volume
      configMap:
        name: customer-config
    - name: secret-volume
      secret:
        secretName: secret-demo
        items:
          - key: spring.datasource.password
            path: password
</code></pre>
<p>If I move spring.datasource.password prop from secret to configmap then it works fine or If I populate its value as env variable then also work fine.
But as we know both are not secure way to do so, can someone tell me what's wrong with file mounting for secrets.</p>

<p>Spring Boot 2.4 added support for <a href="https://docs.spring.io/spring-boot/docs/2.4.3/reference/htmlsingle/#boot-features-external-config-files-configtree" rel="nofollow noreferrer">importing a config tree</a>. This support can be used to consume configuration from a volume mounted by Kubernetes.</p>
<p>As an example, let’s imagine that Kubernetes has mounted the following volume:</p>
<pre><code>etc/
  config/
    myapp/
      username
      password
</code></pre>
<p>The contents of the username file would be a config value, and the contents of password would be a secret.</p>
<p>To import these properties, you can add the following to your application.properties file:</p>
<pre><code>spring.config.import=optional:configtree:/etc/config/
</code></pre>
<p>This will result in the properties <code>myapp.username</code> and <code>myapp.password</code> being set . Their values will be the contents of <code>/etc/config/myapp/username</code> and <code>/etc/config/myapp/password</code> respectively.</p>
