<p>I have configMap:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: my-app
data:
  application.yaml: |-
    config:
      property1: 1
      property2: 2
      property3: 2            
      my-map-property:
        a: b
        c: d
        e: f
        g: h
</code></pre>
<p>now I want to update my map property to:</p>
<pre><code>  my-map-property:
    1: 5
    2: 6
    3: 7
    4: 8
</code></pre>
<p>what is the easiest tool to apply this patch to my configMap ?</p>
<p>I know there is yq or kustomize but when I tried example with kustomize</p>
<pre><code>resources:
- my-configMap.yaml
patchesStrategicMerge:
- patch-configMap.yaml
</code></pre>
<p>and run: <code>kubectl kustomize ./</code> then output contains just patch now whole configMap. Is there some better tool how to deal with this problem ?</p>

<p>You can use yq + kustomize configMap generators. The downside is that Kustomize will mutate the config map name every time there is a change so you will have to &quot;garbage collect&quot; all unused config maps manually.</p>
<p>So you would have the following setup:</p>
<pre class="lang-yaml prettyprint-override"><code># application.yaml
config:
  property1: 1
  property2: 2
  property3: 2
  my-map-property:
    a: b
    c: d
    e: f
    g: h

</code></pre>
<pre class="lang-yaml prettyprint-override"><code># kustomization.yaml
configMapGenerator:
  - name: my-app
    files:
      - application.yaml
</code></pre>
<p>You would then run some yq commands <code>yq e -i '.config.my-map-property.a = 1' application.yaml</code></p>
<p>and finally <code>kubectl kustomize ./</code></p>
<p>Wherever you want to use the config, just reference it as <code>my-app</code>, kustomize will propagate and append the unique identifier to all references.</p>
<p>You can alternatively do something like <code>kubectl create configmap my-app --from-file=application.yaml --dry-run=true -o yaml</code> after running the yq command to mutate the values if you don't want to use Kustomize in your workflow. But I personally prefer using Kustomize.</p>
