<p>We have a spring boot application that is deployed to Kubernetes. We are adding i18n capabilities to this application and want to place the messages.properties file outside the application jar/war. I have been able to do that in spring boot. How will this work when I deploy it on Kubernetes? Do I need to use the configmaps? Following is the code snippet</p>

<pre><code>@Configuration
public class AppConfig {
@Bean
public MessageSource messageSource() {
    ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    //Path to the messages.properties files
    messageSource.setBasenames("file:/messages/messages", "classpath:messages");
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setCacheSeconds(60);
    return messageSource;
}
}
</code></pre>

<p>Yes you can do this with a configmap. It is much the same as accessing an external application.properties file. First you can <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files" rel="noreferrer">create a ConfigMap directly from the file</a> or create a <a href="https://github.com/ryandawsonuk/secrets-treasurehunt/blob/master/treasurehunt/config.yaml" rel="noreferrer">ConfigMap representing the file</a>:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: treasurehunt-config
  namespace: default
data:
  application.properties: |
    treasurehunt.max.attempts=5
</code></pre>

<p>Then in your kubernetes Deployment you create a <a href="https://github.com/ryandawsonuk/secrets-treasurehunt/blob/master/treasurehunt/deployment.yaml#L39" rel="noreferrer">Volume for the ConfigMap</a> and <a href="https://github.com/ryandawsonuk/secrets-treasurehunt/blob/master/treasurehunt/deployment.yaml#L35" rel="noreferrer">mount that into the Pod under the directory you use for the external configuration</a>:</p>

<pre><code>          volumeMounts:
          - name: application-config
            mountPath: "/config"
            readOnly: true
      volumes:
      - name: application-config
        configMap:
          name: treasurehunt-config
          items:
          - key: application.properties
            path: application.properties
</code></pre>

<p>These snippets come from an <a href="https://dzone.com/articles/hunting-treasure-with-kubernetes-configmaps-and-se" rel="noreferrer">example of mounting a Volume from ConfigMap</a> for an application.properties file so they use the spring boot <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files" rel="noreferrer">default external properties file path</a> of <code>/config</code>. You can <a href="https://github.com/ryandawsonuk/secrets-treasurehunt/blob/master/treasurehunt/deployment.yaml#L37" rel="noreferrer">set that in the yaml for the mount</a> so you could mount the file to use the same relative path that you are already using when running outside of kubernetes.</p>
