Wednesday, 11 September 2019

kubernete springboot docker image, setup properties



https://www.exoscale.com/syslog/configuration-management-kubernetes-spring-boot/


https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

if you want to set configurations of your springboot application:

you can put them into your application.properties file.

but if you want to pass them in when you are starting your docker or kubernate, then you can :


docker run myimage:1.0.0 --xxx.var=123
or

docker run --env JAVA_OPTS=-Dxx.var=123 myImage:1.0.0


below doesn't work: (below will set OS envs which springboot configuration doesn't consider)
docker run myimage:1.0.0 -e "xx.var=123"

you need to change xx_var,which means you don't need to change your java code, just add an env called xx_var .

which means in kubernets below will not work:

containers:
      - name: lala
        image: myimage:1.0.0
        env:
        - name: xx.var
          value: 123

but below works:


containers:
      - name: lala
        image: myimage:1.0.0
        env:
        - name: xx_var
          value: 123

and below also work :
containers:
      - name: lala
        image: myimage:1.0.0
        args: ["--xx.var=123 "]

you also can use java option way, but i will not give example here.

summary:

which means if you don't have application.properties, then you can also create local envs, but springboot will not able to find them because most of them name like xx.xx.x  period-separated.  if you define xx.xx.xx in your env, then springboot cannot find them, because springboot auto search for xx_xx_xx_x. interesting?







No comments:

Post a comment