<p>My core dns corefile got corrupted somehow and now I need to regenerate it or reset it to it's default installed value. How do I do that? I've tried copying and pasting a locally-saved version of the file via <code>kubectl edit cm coredns -n kube-system</code> but I get validation errors </p>

<pre><code>error: configmaps "coredns" is invalid                                                                                                                                                                             
A copy of your changes has been stored to "/tmp/kubectl-edit-suzaq.yaml"                                                                                                                                           
error: Edit cancelled, no valid changes were saved.
</code></pre>

user_78361084
<p>When you directly edit the setting, it used to give the error.  </p>

<p>What can you do?</p>

<blockquote>
  <p>before you run anything, please take a backup:</p>
</blockquote>

<pre><code>kubectl -n kube-system get configmap coredns -o yaml &gt; coredns.yaml
</code></pre>

<h3>Ways #1, forcely apply it.</h3>

<pre><code>kubectl apply --force -f /tmp/kubectl-edit-suzaq.yaml
</code></pre>

<p>In most cases, it will apply the latest setting successfully by this way. If failed, go through the error, update the file <code>/tmp/kubectl-edit-suzaq.yaml</code> and forcely apply again.</p>

<h3>Ways #2, delete and apply again.</h3>

<pre><code>kubectl -n kube-system get configmap coredns -o yaml &gt; coredns.yaml

# do a backup, if you don't 100% sure the change will work
cp coredns.yaml coredns.yaml.orig

# update the change in coredns.yaml

# delete coredns
kubectl delete configmap coredns

# apply new change
kubectl apply -f coredns.yaml
</code></pre>

<p>Be careful, above steps will generate outage. if you work on a prod environment, you should think about to backup all kubernetes setting before doing above change.</p>
