<p>I'm trying to add a rewrite to coredns to point a domain to the cluster loadbalancer (so that the request for that domain gets redirected back into the cluster). I can't seem to find a way to affect k3s' coredns configuration. Is there a way to change it?</p>
<p>(This is to work around <a href="https://github.com/jetstack/cert-manager/issues/1292#issuecomment-757283796" rel="nofollow noreferrer">https://github.com/jetstack/cert-manager/issues/1292#issuecomment-757283796</a> where a pod tries to contact another service in the cluster via a DNS name that points to the router's IP, which fails due to how NAT works.)</p>

<p>It is possible to configure <code>CoreDNS</code> to mapping one domain to another domain by adding <code>rewrite</code> rule.
Suppose you have domain <code>example.com</code> and you want that domain to point to <code>google.com</code> domain.</p>
<p>To do this in <code>CoreDNS</code>, you can use the <code>rewrite</code> plugin.</p>
<p>Configuration of <code>CoreDNS</code> is stored in <code>coredns</code> <code>ConfigMap</code> in <code>kube-system</code> namespace.
You can edit it using:<br></p>
<pre><code>root@kmaster:~# kubectl edit cm coredns -n kube-system
</code></pre>
<p>Just add one <code>rewrite</code> rule, like in the example below:<br></p>
<pre><code>apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        rewrite name example.com google.com # mapping example.com to google.com
        ready
...
</code></pre>
<p>Next you need to reload <code>CoreDNS</code>, to use new configuration. You may delete coredns <code>Pod</code> (<code>coredns</code> is deployed as <code>Deployment</code>, so new <code>Pod</code> will be created) or you can send it a <code>SIGUSR1</code> to tell it to reload graceful.</p>
<p>Finally we can check how it works:</p>
<pre><code>root@kmaster:~# kubectl run -it --rm --image=infoblox/dnstools:latest dnstools
dnstools# host -t A google.com
google.com has address 172.217.21.238
dnstools# host -t A example.com
example.com has address 172.217.21.238
</code></pre>
<p>You can find more information about rewrite plugin in <a href="https://coredns.io/plugins/rewrite/" rel="nofollow noreferrer">Coredns rewrite documentation</a>.</p>
