0

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

4
  • 1
    You can use envFrom to map all configmap values to env variables. in spring boot the env variable HEC_POSTGRES_DB_NAME is the same as the java param hec.postgres.db-name. Commented Feb 25, 2022 at 1:03
  • Can u please give me an example Commented Feb 25, 2022 at 3:46
  • 1
    @ronan Have you tried to look into k8s official documentation? Commented Feb 25, 2022 at 10:55
  • 1
    From your question : " Should I create a configMap inside a Spring Boot project and load the DB Values ?" AFIK configMap is part of kubernetes and deployment. It would setup environmental and configuration files inside your kubernetes pod/container. With configMap (see k8s doc) you can provide a "DB_NAMES" as an environmental variable inside your container and your spring-boot apps can read it the same way as any env vars locally (not on k8s). there is plenty of examples on the subject Commented Feb 26, 2022 at 2:50

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you , can u please show an example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.