<p>I have <code>yaml</code> with lines:</p>
<pre><code>accounts:
  service:
    - id: account1
      username: foo
      password: bar
    - id: account2
      username: foo1
      password: bar1
</code></pre>
<p>It's default values for my app. But I want to change it in <code>ConfigMap</code>. I do something like that:</p>
<pre><code>accounts.service[0].id: id0
accounts.service[0].username: username0
accounts.service[0].password: password0

accounts.service[1].id: id1
accounts.service[1].username: username1
accounts.service[1].password: password1

accounts.service[2].id: id2
accounts.service[2].username: username2
accounts.service[2].password: password2

</code></pre>
<p>It doesn't work. How can I do it correctly? The list of objects can be with random size.</p>
<p>And, of course, password I'd like to storage in secrets.</p>

faoxis
<p>If your app, works and can read the yaml as in your example you can create a configMap from your yaml file like so:</p>
<p>kubectl create configmap myconfigmap  --from-file=myfile.yaml --dry-run=client -o yaml &gt; output-configmap-file.yaml</p>
<p>where myfile.yaml is your yaml file.</p>
<p>this will create locally the output-configmap-file.yaml in the right format for Kubernetes.
You can edit this, add namespaces, and what evver you need
kubectl apply -f output-configmap-file.yaml, will create your configmap in the cluster.</p>
<p>Inside your deployment of the app, create a volume with that configMap and mount it inside your container specs.
Like so:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mydeployment
  namespace: mynamespace
  labels:
    app: api
spec:

  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          volumeMounts:
            - name: myyaml
              mountPath: /path/to-your-yaml/myyaml.yaml
              subPath: myyaml.yaml
          image: myimage
.........

........
      volumes:
        - name: myyaml
          configMap:
            name: myconfigMap
</code></pre>
<p>This will take the configMap and mount it as your yaml file inside the container.
So you don't even need to put the file in your image.</p>
<p>Hint: Passwords don't belong inside the configMap. Secrets are better place.</p>
