<p>I have a Kubernetes 1.13.1 cluster with CoreDNS and a number of services running in the default namespace that I'd like to be reachable via <code>&lt;servicename&gt;.nsc</code> in addition to the default <code>&lt;servicename&gt;.default.svc.cluster.local</code>.</p>

<p>The first thing I've tried was manually rewriting each service, like this:</p>

<pre><code>rewrite name gitea.nsc gitea.default.svc.cluster.local
</code></pre>

<p>Running <code>nslookup gitea.nsc</code> returns the expected output:</p>

<pre><code>Server:     10.245.0.10
Address:    10.245.0.10#53

Name:   gitea.nsc
Address: 10.245.64.203
</code></pre>

<p>I can <code>curl</code> it, all is fine.</p>

<p>But then I tried abstracting this somewhat, as manually adding a line for each service is tedious.</p>

<p>I ended up with this:</p>

<pre><code>rewrite name suffix .nsc .default.svc.cluster.local
</code></pre>

<p>But now, <code>curl</code>ing suddenly fails. <code>nslookup</code> gives a possible clue as to why:</p>

<pre><code>Server:     10.245.0.10
Address:    10.245.0.10#53

Name:   gitea.default.svc.cluster.local
Address: 10.245.64.203
</code></pre>

<p>Now the name in the response contains the rewritten host, not the original input. My guess is that this throws off <code>ping</code>, <code>curl</code>, <code>wget</code>. </p>

<p>My Corefile currently looks like this:</p>

<pre><code>.:53 {
        errors
        health
        rewrite name git.nsc gitea.default.svc.cluster.local
        rewrite name suffix .nsc .default.svc.cluster.local
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }
</code></pre>

<p>Everything apart from the two rewrite lines is autogenerated by my hosting provider. I'm using <code>git.nsc</code> in one case so I can have both rewrites in the Corefile simultaneously while I'm debugging this.</p>

<p>I'm puzzled. How do I get CoreDNS to rewrite <code>&lt;servicename&gt;.nsc</code>, yet not return the rewritten host in its response?</p>

1flx
<p>Turns out the answer is right in the <a href="https://github.com/coredns/coredns/blob/master/plugin/rewrite/README.md" rel="nofollow noreferrer">rewrite plugin Readme</a>. Summarizing:</p>

<p>As it turns out, exact rewrites like my <code>git.nsc</code> rewrite above get the response rewritten for free, the default is to return the rewritten host. For other types like regex or suffix, you have to do that explicitly. This is only possible for regex rewrites, so suffix rewrites need to be rewritten to regex rewrites first.</p>

<p>The following snippet works for me:</p>

<pre><code>rewrite stop {
    name regex (.*)\.nsc {1}.default.svc.cluster.local
    answer name (.*)\.default\.svc\.cluster\.local {1}.nsc
}
</code></pre>

<p>The <code>answer name</code> part is basically the <code>name regex</code> part in reverse.</p>
