I would like to know, what's the best practice to handle configs for a Java App in Kubernetes? I have seen some examples with System variables in the yaml file. Or is there a "better" approach with java property files?
Is there also a way to let different instances of a pod use different configurations?
Thanks in advance! Mananana
There is no canonical solution, it depends from case to case
If you have one or a few parameters passing them as environment variables would be ok.
In case if you have many parameters (lets say you have different set of parameters for production and for test environment) it is more convenient to gather them into property file and pass the property file name during application startup. It could be done either using env variable or just as an argument to the startup command.
Property files (or profiles) are also well supported with the popular frameworks, like spring boot, they allow to pass a profile during startup. In this case kubernates yaml could look somehow like this:
env:
- name: SPRING_PROFILES_ACTIVE
value: production
command: [ "bash", "-c", "java -jar App.jar"]