I have to inject DB URL, DB Username and Password variables into a Java Spring Boot Application. I know that these properties reside in the application.properties file under res/ folder.
Now as a design change I want to adopt K8s ConfigMaps and Secrets to be used in place of hardcoding in the the application.properties file.
How can I link the CMs and Secrets from K8s to the application. How should I set placeholders in application.properties file?
Does defining the CM and Secret dependency in application deployment.yaml does everything?
You have two options: one can be achieved without extra dependencies and one with Spring Boot Cloud.
Plain way
You define enviroment variable placeholders in your
application.yml:You then define the environment variables in your k8s deployment:
More on defining environment variables for containers can be found in the k8s documentation.
Spring Boot Cloud Kubernetes
There is a whole section in the reference called Using a ConfigMap PropertySource and Secrets PropertySource. I suggest you go and look it up there.