<p>I have an application.yml (Spring) file, which has almost 70 fields, want to move those fields to ConfigMap.
In the process of setup ConfigMap, have realized all the 70 fields has be flatened example : webservice.endpoint.transferfund
It's gonna be a painful task to convert all the 70 fields as flat, is there any alternative. </p>

<p>Please suggest.</p>

<p>Below Config is working:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: configmapname
  namespace: default
data:
  webservice.endpoint.transferfund: http://www.customer-service.app/api/tf
  webservice.endpoint.getbalance: http://www.customer-service.app/api/balance
  webservice.endpoint.customerinfo: http://www.customer-service.app/api/customerinfo
</code></pre>

<p>Below config is not working, tried it as yml format.</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: configmapname
  namespace: default
data:
  application.yaml: |-
    webservice:
      endpoint:
        transferfund: http://www.customer-service.app/api/tf
        getbalance: http://www.customer-service.app/api/balance
        customerinfo: http://www.customer-service.app/api/customerinfo 
</code></pre>

<p>in src/main/resources/application.yml have below fields to access ConfigMap keys:</p>

<pre><code>webservice:
  endpoint:
    transferfund: ${webservice.endpoint.transferfund}
    getbalance: ${webservice.endpoint.getbalance}
    customerinfo: ${webservice.endpoint.customerinfo}
</code></pre>

<h2>Updated:</h2>

<p>ConfigMap Description:</p>

<pre><code>C:\Users\deskktop&gt;kubectl describe configmap configmapname
Name:         configmapname
Namespace:    default
Labels:       &lt;none&gt;
Annotations:  &lt;none&gt;

Data
====
application.yaml:
----
webservice:
  endpoint:
    transferfund: http://www.customer-service.app/api/tf
    getbalance: http://www.customer-service.app/api/balance
    customerinfo: http://www.customer-service.app/api/customerinfo
Events:  &lt;none&gt;
</code></pre>

<p>Deployment script: (configMapRef name provided as configmap name as shown above)</p>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: configmap-sample
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: configmap-sample
    spec:
      containers:
      - name: configmap-sample
        image: &lt;&lt;image&gt;&gt;
        ports:
        - name: http-api
          containerPort: 9000
        envFrom:
        - configMapRef:
            name: configmapname
        resources:
          limits:
            memory: 1Gi
          requests:
            memory: 768Mi
        env:
        - name: JVM_OPTS
          value: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -Xms768M"   
</code></pre>

<p>A <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/configmap" rel="nofollow noreferrer">ConfigMap</a> is a dictionary of configuration settings. It consists of key-value pairs of strings. Kubernetes then adds those values to your containers.</p>

<p>In your case you have to make them flat, because Kubernetes will not understand them.</p>

<p>You can read in the documentation about <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/" rel="nofollow noreferrer">Creating ConfigMap</a> that:</p>

<blockquote>
  <p><code>kubectl create configmap &lt;map-name&gt; &lt;data-source&gt;</code></p>
  
  <p>where  is the name you want to assign to the ConfigMap and  is the directory, file, or literal value to draw the data from.</p>
  
  <p>The data source corresponds to a key-value pair in the ConfigMap, where</p>
  
  <ul>
  <li>key = the file name or the key you provided on the command line, and</li>
  <li>value = the file contents or the literal value you provided on the command line.</li>
  </ul>
  
  <p>You can use  <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands/#describe" rel="nofollow noreferrer"><code>kubectl describe</code></a>  or  <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands/#get" rel="nofollow noreferrer"><code>kubectl get</code></a>  to retrieve information about a ConfigMap.</p>
</blockquote>

<p><strong>EDIT</strong></p>

<p>You could create a ConfigMap from a file with defined key.</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-the-key-to-use-when-creating-a-configmap-from-a-file" rel="nofollow noreferrer">Define the key to use when creating a ConfigMap from a file</a></p>

<p>Syntax might look like this:</p>

<p><code>kubectl create configmap my_configmap --from-file=&lt;my-key-name&gt;=&lt;path-to-file&gt;</code>
And the ConfigMap migh look like the following:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  creationTimestamp: 2019-07-03T18:54:22Z
  name: my_configmap
  namespace: default
  resourceVersion: "530"
  selfLink: /api/v1/namespaces/default/configmaps/my_configmap
  uid: 05f8da22-d671-11e5-8cd0-68f728db1985
data:
  &lt;my-key-name&gt;: |
    key=value
    key=value
    key=value
    key=value
</code></pre>

<p>Also I was able to find <a href="https://github.com/tumblr/k8s-config-projector" rel="nofollow noreferrer">Create Kubernetes ConfigMaps from configuration files</a>.</p>

<blockquote>
  <h2>Functionality</h2>
  
  <p>The projector can:</p>
  
  <ul>
  <li>Take raw files and stuff them into a ConfigMap</li>
  <li>Glob files in your config repo, and stuff ALL of them in your configmap</li>
  <li>Extract fields from your structured data (yaml/json)</li>
  <li>Create new structured outputs from a subset of a yaml/json source by pulling out some fields and dropping others</li>
  <li>Translate back and forth between JSON and YAML (convert a YAML source to a JSON output, etc)</li>
  <li>Support for extracting complex fields like objects+arrays from sources, and not just scalars!</li>
  </ul>
</blockquote>
