ronan
ronan

Reputation: 4672

Getting Kubernetes Config Map values into application.properties in Spring Boot

In our project we are deploying our Spring Boot based microservices into Azure using Azure Kubernetes Service and we have a Jenkins Job that creates ConfigMaps with appropriate DB names using Azure CLI . Now I want to get the values of DB Names from the ConfigMap created by Jenkins in my Spring Boot application.properties . Jenkins job uses following code to create a configmap in AKS

sh '''
     kubectl --kubeconfig ./temp-config create configmap generic ${PSQL_CONFIG} -n "${HEC_NAMESPACE}" \
     --from-literal=hec.postgres.host=${PSQL_SERVER} \
     --from-literal=hec.postgres.dbNames=[${DB_NAMES}] \
     --dry-run=client -o yaml | kubectl --kubeconfig ./temp-config apply ${DRYRUN} -f 
   '''

Now to get the value of variable DB_NAMES in my Spring Boot app ,

1. Should I create a configMap inside a Spring Boot project and load the DB Values ?

2. Or should I set the DB_NAMES variable in the application.properties like hec.postgres.db-name={DB_NAMES}

Once I have DB_NAMES values populated then I can use the way I want in my Code Please let me know which approach is good

Upvotes: 0

Views: 2377

Answers (1)

P Ekambaram
P Ekambaram

Reputation: 17615

Yes, define DB_NAMES variable and value in configmap object and load the values from configmap as environment variables inside the container. use those environment variables in the springboot properties file.

Upvotes: 3

Related Questions