<p>I am searching for a way to add a specific label to ConfigMap using Kustomize. Using <code>commonLabels</code> is not an option because it adds a label to every resource. For config map generation, I am using the following:</p>
<pre><code>configMapGenerator:
- name: ${REPOSITORY_NAME}-env
  envs:
  - .env
</code></pre>
<p>And I would like to achieve something like this:</p>
<pre><code>configMapGenerator:
- name: ${REPOSITORY_NAME}-env
  labels:
    key: value
  envs:
  - .env
</code></pre>

Bjørson Bjørson
<p>As per this <a href="https://github.com/keleustes/kustomize/tree/allinone/examples/issues/issue_1501" rel="nofollow noreferrer">git link</a> you can add specific labels by using patch files in kustomize.</p>
<blockquote>
<pre><code>apiVersion: v1
data:
  a: &quot;0&quot;
kind: ConfigMap
metadata:
  labels:
    apps: a
  name: a-config-map-26kgmbk2md
</code></pre>
<p>Then add these in the configMapGenerator</p>
<pre><code>configMapGenerator:
  - name: a-config-map
    envs:
      - a.properties
patchesStrategicMerge:
  - patch-a.yaml
</code></pre>
</blockquote>
<p>This will add the specific label to individual configMaps to the configmap generator.</p>
<p>Additionally you can also refer to this <a href="https://github.com/kubernetes-sigs/kustomize/issues/3108#issuecomment-710344736" rel="nofollow noreferrer">git issue</a> for additional information.</p>
