title: How to replace existing configmap in kubernetes using helm
body: <p>I want to replace coredns configmap data in kube-system namespace as below.</p>
  <p>First snippet:</p>
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
  name: Corefile
  data:
   abc:53 {
   log
   errors
   cache 30
   forward . IP1 IP2 IP3
   }
   xyz:53 {
   log
   errors
   cache 30
   forward . IP1 IP2 IP3
   }
  </code></pre>
  <p>But I want to read from values.yaml and create data of configmap based on values. I have created template as below for that in helm inside templates directory. When I do helm install, it throws error saying &quot;coredns&quot; configmap already exists.</p>
  <p>Second snippet:</p>
  <pre><code>apiVersion: v1
  kind: ConfigMap
  metadata:
  name: coredns
  data: 
   Corefile: | 
   {{- range $domain := splitList &quot; &quot; .Values.dns_int_domains }}
   $domain:53 {
   log
   errors
   cache 30
  {{- range $dns_int_server := splitList &quot; &quot; .Values.dns_int_servers }}
  {{- if $dns_int_server }}
  forward . $dns_int_server 
  {{- end }}
  }
  {{- end }}
  </code></pre>
  <p>If I give kubectl apply or kubectl create configmap command, it is created with data as in second snippet and not as rendered data(first snippet). How to create or replace an existing configmap data with rendered output of above code ?</p>
  <p>Some example on the internet shows creating configmap with different name &quot;custom-coredns&quot;. But I am not sure what are additional changes needs to be done on coredns deployment to take new configmap data for its Corefile. I see below in describe pods output of coredns pod.</p>
  <pre><code>Args:
        -conf
        /etc/coredns/Corefile
  </code></pre>
  <p>My requirement is to replace the Corefile data instead of preparing data manually and then kubectl apply, I want to automate it either in helm reading values from values.yaml or somehow. Expecting any way to achieve this.</p>
  <p>It would be grateful if someone helps me out. Thanks in advance!!!</p>