<p>I'm using rke2 cluster, i.e. a k8s distribution.</p>
<p>And I want to add a nameserver for '*.example.org' to the cluster DNS system, for which I should change the core file of coredns like below.</p>
<pre><code>.:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        forward . 172.16.0.1
        cache 30
        loop
        reload
        loadbalance
    }
    example.org:53 { #加一个block
        errors
        cache 30
        forward . 10.150.0.1
    }
</code></pre>
<p>However, rke2 install coredns with helm system, so I should change the helm values to add somethings to the corefile.</p>
<p>How should I achieve this. Thank you a lot.</p>

<p>You map or edit the configmap like</p>
<p>you can map the domain to the service name using <strong>rewrite</strong>, <code>rewrite name example.io service.default.svc.cluster.local</code></p>
<pre><code>rewrite name example.io service.default.svc.cluster.local
loadbalance round_robin
prometheus {$POD_IP}:9153
forward . /etc/resolv.conf
reload
</code></pre>
<p>YAML for ref</p>
<pre><code>apiVersion: v1
data:
  Corefile: |-
    .:5353 {
        bind {$POD_IP}
        cache 30
        errors
        health {$POD_IP}:8080
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        rewrite name example.io service.default.svc.cluster.local
        loadbalance round_robin
        prometheus {$POD_IP}:9153
        forward . /etc/resolv.conf
        reload
    }
kind: ConfigMap
metadata:
  labels:
    app: coredns
    k8s-app: coredns
  name: coredns
  namespace: kube-system
</code></pre>
<p>Other answers for ref :</p>
<ul>
<li><a href="https://stackoverflow.com/a/73078010/5525824">https://stackoverflow.com/a/73078010/5525824</a></li>
<li><a href="https://stackoverflow.com/a/70672297/5525824">https://stackoverflow.com/a/70672297/5525824</a></li>
</ul>
