Kubernetes configmap name is not picked up by springboot application Kubernetes configmap name is not picked up by springboot application kubernetes kubernetes

Kubernetes configmap name is not picked up by springboot application


That's not the name of the ConfigMap, it's the name of the kubernetes namespace in which it's running, as seen here, showing that in your example the "name" is application.

You didn't actually say whether you tested the RestController, to say what it returns (and/or emits to stdout); did your GET produce any output, or are you asking this question solely based on that log message?


bootstrap.yml

 spring: application:  name: echo-configmap

I can't tell if you have just mis-copy-pasted, but if you really do have the spring: key indented in your bootstrap.yml, then that file will be mis-parsed by Spring, causing the spring.application.name to not be what you think.


data:  application.yml: |-    bean:      message: Hello from Kubernetes Configmap...@EnableConfigurationProperties@ConfigurationProperties(prefix = "bean")

Foremost, you are treading on thin ice by naming your ConfigurationProperties prefix a very generic word like bean. Secondarily, you are making things harder by causing your RestController to serve as your ConfigurationProperties instance, too, since they have very, very different lifecycles within Spring. Thirdly, I would need to test it to say with certainty, but @Value is traditionally used to inject a SPeL value into some other bean, not a random field in the ConfigurationProperties -- you'll get a lot further by just making message into a normal JavaBean property via its getMessage()/setMessage() accessor/mutator pattern. Plus, doing it that way has the very, very real benefit that you can set a breakpoint inside the get or set method and see for yourself that Spring is calling them with the values you expect.


The issue was that I didn't package my application.properties in the JAR file. Hence the application name was not read. After fixing the packaging it worked