<p>I've got a spring boot service that presently uses <code>.properties</code> file for consuming variables using the spring @Value annotation. Recently we have been migrating the spring boot service to K8 cluster. This means that, we need to create a <code>configmap.yml</code> file containing all the same properties as the <code>.properties</code> file. And whenever changes to properties are made, it must be done in both places, the configmap and <code>.properties</code> file used for local dev. So we have to manage 2 files (configmap and .properties) for each spring profile. Is there a better way to do this? We use gitlab ci/cd tools for deployment.</p>

<p>Is there a way to use the configmap instead of the properties for local development in our machines, so that we can discard the .properties file altogether and only maintain configmap? </p>

<p>What's the ideal way to manage properties for the spring boot application?</p>

<p>Sample service-config-map.yaml</p>

<pre class="lang-yaml prettyprint-override"><code>kind: ConfigMap 
apiVersion: v1 
metadata:
  name: myservice-config
data:
  server.port: "10300"
  spring.application.name: myserviceGateway
  myservice.application.name: helloworld
  myservice.server.apiContext: /api
  myservice.server.versionContext: /v
  myservice.current.version=2.0

</code></pre>

<p>properties file <code>application.properties</code></p>

<pre><code>server.port=10300
spring.application.name=myserviceGateway
myservice.application.name=helloworld
myservice.server.apiContext=/api
myservice.server.versionContext=/v
myservice.current.version=2.0
</code></pre>

<p>The <a href="https://cloud.spring.io/spring-cloud-kubernetes/reference/html/" rel="nofollow noreferrer">Spring Cloud Kubernetes project</a> makes Kubernetes <code>ConfigMap</code>s available during application bootstrapping and triggers hot reloading of beans or Spring context when changes are detected on observed <code>ConfigMap</code>s.</p>

<p>An example <a href="https://github.com/spring-cloud/spring-cloud-kubernetes/tree/master/spring-cloud-kubernetes-examples/kubernetes-reload-example" rel="nofollow noreferrer">here</a></p>

<p>The bootstrap yaml which has the name of the config map looks like</p>

<pre><code>spring:
  application:
    name: reload-example
  cloud:
    kubernetes:
      reload:
        enabled: true
        mode: polling
        period: 5000
      config:
        sources:
          - name: other
          - name: ${spring.application.name}
</code></pre>
