<p>I had a project that wanted to update the DNS configuration of Pod with Operator,</p>
<pre><code>get dns message
get matched pod
modify:
    pod.Spec.DNSConfig = CRD_SPEC
    pod.Spec.DNSPolicy = corev1.DNSNone
client.Update(ctx,&amp;pod)
</code></pre>
<p>But when I implemented it, I got the following error:</p>
<pre><code> ERROR   controller-runtime.manager.controller.dnsinjection      Reconciler error        {&quot;reconciler group&quot;: &quot;xxxx&quot;, &quot;reconciler kind&quot;: &quot;xxxxx&quot;, &quot;name&quot;: &quot;dnsinjection&quot;, &quot;namespace&quot;: &quot;default&quot;, &quot;error&quot;: &quot;Pod \&quot;busybox\&quot; is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)\n  core.PodSpec{\n  \t... // 21 identical fields\n  \tPriority:         &amp;0,\n  \tPreemptionPolicy: nil,\n  \tDNSConfig: &amp;core.PodDNSConfig{\n  \t\tNameservers: []string{\n  \t\t\t\&quot;1.2.3.4\&quot;,\n- \t\t\t\&quot;0.0.0.0\&quot;,\n  \t\t},\n  \t\tSearches: []string{\&quot;ns1.svc.cluster-domain.example\&quot;, \&quot;my.dns.search.suffix\&quot;},\n  \t\tOptions:  []core.PodDNSConfigOption{{Name: \&quot;ndots\&quot;, Value: &amp;\&quot;2\&quot;}, {Name: \&quot;edns0\&quot;}},\n  \t},\n  \tReadinessGates:   nil,\n  \tRuntimeClassName: nil,\n  \t... // 3 identical fields\n  }\n&quot;}
</code></pre>
<p><code>DNSConfig</code> and <code>DNSPoicy</code> fields are not declared to be unable to be <strong>updated</strong> in the source code, so why did the update fail?</p>
<p>I got the same error with <code>kubect edit pod busybox</code> and <code>kubectl apply -f modifyed_pod.yml(add DNSConfig)</code> command.</p>
<p>I would appreciate it if you could tell me how to solve it.</p>

<p>Like the message says you cannot update a DNS config of a pod: <code>Forbidden: pod updates may not change fields other than spec.containers[*].image, spec.initContainers[*].image</code>.</p>
<p>If you want to inject a DNS config into all pods you need to add the configuration before the pod is created. Look into <a href="https://medium.com/ibm-cloud/diving-into-kubernetes-mutatingadmissionwebhook-6ef3c5695f74" rel="nofollow noreferrer">MutatingAdmissionWebhook</a> as an approach for this.</p>
