<p>I'm new to java and k8, and  I have some doubts about how to handle application configurations for my java apps. I've got one spring boot app and the other three use wildfly.</p>

<p>So, they all got hardcoded application configurations, and when starting them the just use something like:</p>

<pre><code>java -Dswarm.project.stage=development -jar foobar/target/foobar-swarm.jar
</code></pre>

<p>except for the spring boot which has an <strong>application.properties</strong> file that consists of application configuration data.</p>

<p>So basically the three java apps have  backed in two files (which I know is a no no):</p>

<pre><code> - project-stages.yml
 - standalone.xml
</code></pre>

<p>And when the developer wants to deploy to production he uses:</p>

<pre><code>  java -Dswarm.project.stage=production -jar foobar/target/foobar-swarm.jar
</code></pre>

<p>And, now we come to kubernetes which has three ways of dealing with application configuration data:</p>

<pre><code>1.) Env variables

2.) Config maps

3.) Secrets
</code></pre>

<p>I was thinking of using <strong>configmaps</strong> instead of env variables because they have more <a href="https://medium.com/google-cloud/kubernetes-configmaps-and-secrets-68d061f7ab5b" rel="nofollow noreferrer">benefits</a>.</p>

<p>So, the developer gave me the possibility of overwriting those hardcoded variables with an external file : <strong>Dsystem.properties.file=/var/foobar/environment.properties</strong></p>

<p>But I'm still overwriting an hardcoded files with an external file, and I'm not happy with that solution!</p>

<p>So, I'm basically looking on advise can those hardcoded files be supplied externally and populated with configmaps in k8 - what would be the best practice of handling the config files in the world of k8?</p>

<p>Tnx,
Tom</p>

<p>There are several questions in the post, but I can address only the one related to spring-boot. </p>

<p>The simplest and the most convenient way of specifying configurations to spring boot app is via its built in profiling feature. As you already mentioned you have <code>application.properties</code>. You can create similar files according to your usage cases: <code>application-production.properties</code>, <code>application-staging.properties</code>, <code>application-k8s.properties</code>, etc. 
Kubernetes deployment doesn't change this in any way.
You can control which configuration to pick by setting <code>SPRING_PROFILES_ACTIVE</code> env variable from the kubernetes.</p>

<p>You might have something like this:</p>

<pre><code>docker run -e SPRING_PROFILES_ACTIVE=k8s -d -p 0.0.0.0:8080:8080 \
    --name=yourapp your_image_name bash -c "java -jar yourapp.jar"
</code></pre>

<p>It will pick configuration from <code>application-k8s.properties</code>.</p>

<p>Configuration files support environment variables as well.
You can have placeholders like <code>${YOUR_DB}</code> in your properties files and Spring will automatically pick up env variable with name <code>YOUR_DB</code>. It is convenient to use this feature let's say when your app pod must have its own db pod.</p>
