<p>New to k8s.</p>

<p>Went through <a href="https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/2.1.0.RC1/multi/multi__kubernetes_propertysource_implementations.html" rel="nofollow noreferrer">https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/2.1.0.RC1/multi/multi__kubernetes_propertysource_implementations.html</a></p>

<p>I am having multi profiles in config map and want my app to pickup the properties based on the spring.profiles.active.</p>

<p><strong>Case 1:-</strong></p>

<p>My ConfigMap looks like,</p>

<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: example-configmap-overriding-new-02
data:
  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
    ---
    spring.profiles = qa
    globalkey = global key qa value
    TeamName = Team Name qa value
    Purpose = Purpose qa value
    RootFile = Root file qa value
    ---
    spring.profiles = prod
    globalkey = global key prod value
    Company = company prod value
    Place = Place prod value
    Country = Country prod value
</code></pre>

<p>My deployment file looks like,</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata: 
  name: demo-configmapsingleprofile
spec:  
  selector:
    matchLabels:
      app: demo-configmapsingleprofile
  replicas: 1
  template: 
    metadata:
      labels:
        app: demo-configmapsingleprofile
    spec:
      serviceAccountName: config-reader
      containers:
      - name: demo-configmapsingleprofile
        image: image name
        ports:
        - containerPort: 8080
        envFrom:
          - configMapRef:
              name: example-configmap-overriding-new-02
        securityContext:
            privileged: false        
</code></pre>

<p>My Config file in spring boot looks like,</p>

<pre><code>@Configuration
public class ConfigConsumerConfig {

@Value(value = "${globalkey}")
private String globalkey;

@Value(value = "${TeamName}")
private String teamName;

@Value(value = "${Purpose}")
private String purpose;

@Value("${RootFile}")
private String rootFile;

@Value("${Company}")
private String company;

@Value("${Place}")
private String place;

@Value("${Country}")
private String country;

//With getters and setters
}
</code></pre>

<p>My application.properties looks like,</p>

<pre><code>spring.profiles.active=prod
spring.application.name=example-configmap-overriding-new-02
spring.cloud.kubernetes.config.name=example-configmap-overriding-new-02
spring.cloud.kubernetes.config.namespace=default
spring.cloud.kubernetes.config.sources[0].name=example-configmap-overriding-new-02
spring.cloud.kubernetes.config.enabled=true
</code></pre>

<p><strong>App is starting fine and it grabbed the values from the config map. But it is picking from wrong profile. Some values are picked up from qa profile.</strong> </p>

<p>I am getting the final result as:-</p>

<pre><code>{"globalkey":"global key prod value","teamName":"Team Name qa value","purpose":"Purpose qa value","rootFile":"Root file qa value","company":"company prod value","place":"Place prod value","country":"Country prod value"}
</code></pre>

<p><strong>Case 2:-</strong></p>

<p>But, when I used the config map with yaml, as given below,</p>

<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: example-configmap-overriding-new-02
data:
  application.yml: |-    
    globalkey : global key value
    TeamName : Team Name value
    Purpose : Purpose value
    RootFile : Root file value
    Company : company value
    Place : Place value
    Country : Country value
    ---
    spring:
      profiles: qa
    globalkey : global key qa value
    TeamName : Team Name qa value
    Purpose : Purpose qa value
    RootFile : Root file qa value
    ---
    spring:
      profiles: prod
    globalkey : global key prod value
    Company : company prod value
    Place : Place prod value
    Country : Country prod value
</code></pre>

<p><strong>I am getting the result as expected. It picks from prod profile as expected.</strong></p>

<pre><code>{"globalkey":"global key prod value","teamName":"Team Name value","purpose":"Purpose value","rootFile":"Root file value","company":"company prod value","place":"Place prod value","country":"Country prod value"}
</code></pre>

<p><strong>Case 2 is working as expected but not the Case 1.</strong></p>

<p>Am I doing any mistake/misunderstanding with config map. Could some one advice here?</p>

<p>Thx.</p>

NANDAKUMAR THANGAVELU
<p>Given that there are no other answers yet...let me try to help you.</p>

<p>The <code>---</code> divider in a YAML file separates multiple YAML documents. Not so in a properties file. Not sure how the properties file gets loaded at all with those <code>---</code> but otherwise the way it is structured right now it leads to duplicate keys where a key overwrites the same key before it.</p>

<p>Create multiple key/value pairs - one for each profile - when using properties files. Something like this:</p>

<pre><code>kind: ConfigMap
apiVersion: v1
metadata:
  name: example-configmap-overriding-new-02
data:
  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-qa.properties: |-
    spring.profiles = qa
    globalkey = global key qa value
    TeamName = Team Name qa value
    Purpose = Purpose qa value
    RootFile = Root file qa value
  application-prod.properties: |-
    spring.profiles = prod
    globalkey = global key prod value
    Company = company prod value
    Place = Place prod value
    Country = Country prod value
</code></pre>

<p>They will "materialize" inside a running container as individual files at the mounted location.</p>
