How can I specify the spring.profiles.active param with a value from an environment variable using fabric8 maven plugin? How can I specify the spring.profiles.active param with a value from an environment variable using fabric8 maven plugin? kubernetes kubernetes

How can I specify the spring.profiles.active param with a value from an environment variable using fabric8 maven plugin?


Another way that also worked was explicitly defining it in the JAVA_OPTIONS parameters:

spec:  template:    spec:      containers:      - env:        - name: JAVA_OPTIONS          value: "-Dspring.profiles.active=${ENVIRONMENT}"        - name: ENVIRONMENT          valueFrom:              configMapKeyRef:                  name: global-configmap                  key: ENVIRONMENT


One thing to note first is that the name given to the environment variable injected into the Pod and the key being used from the configmap don't have to match. So you could do:

      - env:        - name: SPRING_PROFILES_ACTIVE          valueFrom:              configMapKeyRef:                  name: global-configmap                  key: ENVIRONMENT

If ENVIRONMENT is a key within the configmap called global-configmap. If it's not then naturally you want to use whatever the key is that matches the value you're looking for (something like spring.profiles.active might be clearer if possible but from your description it sounds like you have an existing configmap called global-configmap with the key called ENVIRONMENT). I expect you'll need to call the environment variable (the name section) SPRING_PROFILES_ACTIVE because this will match to the property spring.profiles.active by relaxed binding.

Alternatively, you do have other options with the fabric8 maven plugin, which it seems you're using for generation. You could simply set an environment variable directly or set the spring.profiles.active value directly in your property file, which you could mount as a configmap.