<p>I am deploying a Spring boot application to Kubernetes. My Docker file is as follows.</p>
<pre><code>FROM alpine-jdk1.8:latest

RUN mkdir -p /ext/app

COPY target/app-service.war /ext/app

ENV JAVA_OPTS=&quot;&quot; \
    APPLICATION_ARGS=&quot;&quot;

CMD java ${JAVA_OPTS} -jar /ext/app/app-service.war ${APPLICATION_ARGS}
</code></pre>
<p>I have many config files under conf directory, but there are secrets also.</p>
<p>So, moved few of them to secrets and few to configMaps in Kubernetes. But, created more than 1 configmaps and secrets to groups configs and secrets.</p>
<p>Since, there are many configMaps and secrets, I had to create many volume mounts and volumes and used the Spring config location to add all these volumes to the classpath as a comma separated values.</p>
<pre><code>- name: APPLICATION_ARGS
  value: --spring.config.location=file:/conf,.....
</code></pre>
<p>Is there any other better approach?</p>

<p>That is a good approach for secrets, but less so <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">for configMaps</a>.</p>

<p>If your war application can rely on environment variable, a possible approach is to convert that configMap into an rc file (file with properties) which can then be read once by the application and used</p>

<p>You can see an example of such an approach in "<a href="http://blog.knuthaugen.no/2016/06/kubernetes-wars-day-3/" rel="nofollow noreferrer"><strong>The Kubernetes Wars</strong></a>" from <a href="https://twitter.com/knuthaug" rel="nofollow noreferrer"><strong>knu:t hæugen</strong></a>:</p>

<blockquote>
  <p>How to deal with configuration?<br>
  Kubernetes likes app config in environment variables, not config files.<br>
  This is easy in our node apps using <a href="https://github.com/mozilla/node-convict" rel="nofollow noreferrer">convict</a>, pretty easy in our ruby apps and ranging from relatively easy to bloody hard in our java apps. </p>
  
  <p>But how to get config into the replication controllers? We opted for using configmaps (a kubernetes object) to store the config, reference the variables from the rc files and maintain it in git controlled files.<br>
  So when we want to change to app config, update the config files and run a script which updates the configmap and reloads all the pods for the app</p>
</blockquote>
