<p>I am new to kubernetes and have a requirement to externalize the properties file of the springboot application using k8s configmap on openshift platform. I have saved the properties file in a git repo as
<em>&quot;greeter.message=Spring Boot myapplication.properties has been mounted as volume on Kubernetes!&quot;</em>
and created the configmap using <em>&quot;oc create configmap myconfig --from-file=myapplication.properties&quot;</em> command.
I can see the same using <em>&quot;oc get configmap myconfig -o yaml&quot;</em> command too as:</p>
<pre><code>data:
  myapplication.properties: greeter.message=Spring Boot myapplication.properties has been mounted as volume on Kubernetes!
    on Kubernetes!
kind: ConfigMap
metadata:
  creationTimestamp: 2021-08-24T04:45:27Z
  name: myconfig 
  namespace: mynamespace
  resourceVersion: &quot;53471&quot;
  selfLink: /api/v1/namespaces/default/configmaps/myconfig
  uid: 73ca674c-8afc-71e1-9a8a-7da609902085
</code></pre>
<p>Now I am having a springboot rest controller as</p>
<pre><code> @RestController
@Slf4j
public class GreeterController {

    @Value(&quot;${greeter.message}&quot;)
    private String greeterMessageFormat; 

    @GetMapping(&quot;/greet/{user}&quot;)
    public String greet(@PathVariable(&quot;user&quot;) String user) {
        return String.format(greeterMessageFormat);
    }
}
</code></pre>
<p>Finally, I made changes to the deployment file for creating and mounting volumes as</p>
<pre><code>spec:
      containers:
          volumeMounts:
          - name: application-config 
            mountPath: &quot;/etc/config&quot; 
            readOnly: true
      volumes:
      - name: application-config
        configMap:
          name: myconfig
</code></pre>
<p>Now issue arises when I try to start the pod, the springboot application fails to start, showing that it could not find any value for ${greeter.message} in @Value(&quot;${greeter.message}&quot;) as I do not have any such property inside the application src/main/resources/app.properties and if I provide one then my springboot application picks that property from the src/main/resources/app.properties instead of the configmap.</p>
<pre><code>Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'greeter.message' in value &quot;${greeter.message}&quot;
</code></pre>
<p><em>It is expected that the value should be taken from the configmap that I created.
Please help me where I am missing anything.</em></p>
<p>I have referred this <em><a href="https://developers.redhat.com/blog/2017/10/03/configuring-spring-boot-kubernetes-configmap#cm-as-files" rel="nofollow noreferrer">https://developers.redhat.com/blog/2017/10/03/configuring-spring-boot-kubernetes-configmap#cm-as-files</a></em> for the same and did the exact.</p>
<p>Thanks in Advance.</p>

coderrabit
<p>Try</p>
<pre><code>   envFrom:                ##Reference all key-value pairs of the sepcial-config ConfigMap. 
   - configMapRef:
       name: myconfig
</code></pre>
<p>References:</p>
<p><a href="https://www.exoscale.com/syslog/configuration-management-kubernetes-spring-boot/" rel="nofollow noreferrer">https://www.exoscale.com/syslog/configuration-management-kubernetes-spring-boot/</a>
<a href="https://www.alibabacloud.com/help/doc-detail/86556.htm" rel="nofollow noreferrer">https://www.alibabacloud.com/help/doc-detail/86556.htm</a></p>
