Multi profile config map is not properly injected to container

7/4/2019

New to k8s.

My configmap looks like

apiVersion: v1
kind: ConfigMap
metadata:
    name: example-configmap-overriding-new-01
data:
    application.properties: |
        globalkey = global key value
        TeamName = Team Name value  
        #Some other key value pairs         
    application-qa.properties: |
        globalkey = global key qa value
        TeamName = Team Name qa value
        #Some other key value pairs
    application-prod.properties: |
        globalkey = global key prod value
        Company = company prod value
        #Some other key value pairs

While trying to use this config map in my spring boot application, app is not picking up the value from the configmap. It says,

Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: 
Could not resolve placeholder 'globalkey' in value "${globalkey}"

Posted that question HERE.

Unfortunatly, saw the env varibles injected inside the container by the configmap. Shared the logs for reference.

application.properties=globalkey = global key value
TeamName = Team Name value
Purpose = Purpose value
RootFile = Root file value
Company = company value
Place = Place value
Country = Country value

application-prod.properties=globalkey = global key prod value
Company = company prod value
Place = Place prod value
Country = Country prod value

application-qa.properties=globalkey = global key qa value
TeamName = Team Name qa value
Purpose = Purpose qa value
RootFile = Root file qa value

#Some other key values pairs injected by k8s

I believe, from the logs, "application.properties=globalkey = global key value", have not seen such key value pair.

Suspect, something went wrong in injecting the configmap. Is there any syntax mistake or?

PS:- I also tried the following syntax too.

apiVersion: v1
kind: ConfigMap
metadata:
    name: example-configmap-overriding-new-01
data:
    application.properties: |-
        globalkey = global key value                    
    application-qa.properties: |-
        globalkey = global key qa value

I am using minikube for local development in windows 10 pro machine.

Could some one share insights here.

PS: I am asking why env variable is displayed as "application.properties=globalkey = global key value" and I also linked the origin of the question. In old question, I asked like "cannot read from configmap". In new question, I asked like, "multi profile config map is not properly injected to container"

-- NANDAKUMAR
application.properties
configmap
kubernetes
minikube
spring-boot

1 Answer

7/10/2019

There are some syntax mistakes with your ConfigMap. Please, try this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-configmap-overriding-new-01
  namespace: <insert_namespace_here>
data:
  application.properties: |
    globalkey=global-key-value
    TeamName=Team-Name-value  
    #Some other key value pairs         
  application-qa.properties: |
    globalkey=global-key-qa-value
    TeamName=Team-Name-qa-value
    #Some other key value pairs
  application-prod.properties: |
    globalkey=global-key-prod-value
    Company=company-prod-value
    #Some other key value pairs

If you are not sure about your configuration, please see this documentation. There are plenty of examples.

Please let me know if that helped.

-- OhHiMark
Source: StackOverflow