Spring Config Location pointing to a Kubernetes Persistent Volume

2/17/2018

Our application landscape consists of Spring Boot apps hosted on docker containers managed by Kubernetes. In Spring Boot, we use the property "spring.config.location" to specify the external location of the property files. The java command is as follows: java -jar myproject.jar --spring.config.location={file://some file path}

Now instead of using the local file path, can I create a Kube persistent volume and give that path in the above command? What Kube volume type should I use to allow for the same semantics of file://{file path} ?

-- Narendra Naidu
kubernetes
spring

1 Answer

2/21/2018

We could successfully read application.properties file from a Kubernetes Persistent Volume using the "spring.config.location" command line argument. The steps we followed were as follows:

  1. Created a persistent volume on Kubernetes (PVC was set to ReadWriteMany option, as multiple microservices will use the same properties file).

  2. Mounted the volume to the Pod of each microservice (changes in the pod script file). Mounted file system accessible via - '/shared/folder/properties' path.

  3. Added the "spring.config.location" parameter to the "java -jar" command - e.g. java -Dspring.profiles.active=$spring_profile -Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -jar myJar.jar --spring.config.location=file:/shared/folder/properties

-- Narendra Naidu
Source: StackOverflow