Kubernetes - Setting classpath

6/30/2018

I am deploying a Spring boot application to kubernetes. My docker file is as follows.

FROM alpine-jdk1.8:latest

RUN mkdir -p /ext/app

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

ENV JAVA_OPTS="" \
    APPLICATION_ARGS=""

CMD java ${JAVA_OPTS} -jar /ext/app/app-service.war ${APPLICATION_ARGS}

I have many config files under conf directory, but there are secrets also.

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.

Since, there are many configMaps and secrets, i had to create many volume mounts and volumes and used the spring confg location to add all these volumes to the classpath as a comma separated values.

- name: APPLICATION_ARGS
  value: --spring.config.location=file:/conf,.....

Is there any other better approach?

Thanks

-- user1578872
docker
kubernetes

1 Answer

6/30/2018

That is a good approach for secrets, but less so for configMaps.

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

You can see an example of such an approach in "The Kubernetes Wars" from knu:t hæugen:

How to deal with configuration?
Kubernetes likes app config in environment variables, not config files.
This is easy in our node apps using convict, pretty easy in our ruby apps and ranging from relatively easy to bloody hard in our java apps.

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.
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

-- VonC
Source: StackOverflow