5

Using helm I am setting the SPRING_PROFILES_ACTIVE as a dev or prod based on the environment. But now I want to load properties from kubernetes configMap based on the activated profile.

Below is the sample configMap

apiVersion: v1
data:
  application-dev.properties: |-
    spring.profiles=dev
    host=hello-dev
  application-prod.properties: |-
    spring.profiles=prod
    host=hello-prod
  application.properties: |-
    host: hello-app
kind: ConfigMap

I am using io.fabric8 kubernetes dependency to use configMap in order to replace the spring cloud config server.

Output of sample API to fetch host property always gives the values as "hello-app" even though dev profile is activated.

Please suggest any method of solving the issue.

Thanks

ravi
  • 51
  • 3
  • I had same requirements. You probably have custom script to dynamically create bootstrap.yaml on the air based on mounted config file. – Kane Nov 06 '18 at 03:56
  • There's now a spring cloud project based on the fabric8 spring cloud kubernetes. Within there you can find https://github.com/spring-cloud/spring-cloud-kubernetes/blob/master/spring-cloud-kubernetes-config/src/test/resources/application-with-profiles.yaml I'm not sure the fabric8 version has the same support - see also https://github.com/spring-cloud/spring-cloud-kubernetes/issues/106 – Ryan Dawson Nov 06 '18 at 13:36
  • 1
    Thanks Kane and Ryan, I switched to use spring-cloud-kubernetes which has the support to have multiple profiles in the configMaps. But for this to work I need to update my spring boot to 2.1.0 from 1.5.8 – ravi Nov 07 '18 at 06:46
  • Hi @ravi: I am also facing the same issue. Spring boot is not picking up any profile other than the default application.properties from the configmap. If your issue is fixed, could u share any github for the example? Thx in advance. – NANDAKUMAR THANGAVELU Jul 05 '19 at 06:53

1 Answers1

-1

apiVersion: v1
kind: ConfigMap
data:
application.yaml: |-
host: hello-app
---
spring:
profiles: dev
host: hello-dev