<p>Using Kubernetes, I'm trying to map *.api requests to *.<br>
<a href="https://stackoverflow.com/questions/54509142/coredns-suffix-rewrite-causes-dns-queries-to-return-the-rewritten-name">I found this thread</a> which helps me how to achieve this and it's working by updating the CoreDNS configuration.<br>
But I would like to do this via a yaml apply so it can be easily deployed to different environments. Also if the CoreDNS config changes in a later release, I won't be getting those changes.<br>
So my question is, how could I apply a yaml file to achieve this:</p>

<pre><code>rewrite stop {
    name regex (.*)\.api {1}.some-namespace.svc.cluster.local
    answer name (.*)\.some-namespace\.svc\.cluster\.local {1}.api
}
</code></pre>

<p>I found this article: <a href="https://learn.microsoft.com/en-us/azure/aks/coredns-custom" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/aks/coredns-custom</a><br>
But I'm unable to figure out how I can use that example for my use-case.</p>

<p>Given that there are no other answers yet, let me describe a possible approach...two, actually.</p>

<p>The main idea is to use CoreDNS' <a href="https://coredns.io/plugins/import/" rel="nofollow noreferrer">import</a> directive - "...The import plugin can be used to include files into the main configuration". And from the CoreDNS manual - "...This plugin is a bit special in that it may be used anywhere in the Corefile".</p>

<p>One option (#1) is to edit the <code>coredns</code> configMap to add <code>import</code> directive to include configuration from another file like in these configMap-s for <a href="https://github.com/Azure/aks-engine/blob/v0.42.2/parts/k8s/addons/coredns.yaml#L62" rel="nofollow noreferrer">AKS</a> and <a href="https://github.com/rancher/k3s/blob/60801e215316c95dd4e65e0203556376a2ca6dd1/manifests/coredns.yaml#L58" rel="nofollow noreferrer">k3s</a>; then add a new volume in the deployment config - see <a href="https://github.com/Azure/aks-engine/blob/v0.42.2/parts/k8s/addons/coredns.yaml#L171-L173" rel="nofollow noreferrer">here</a> and <a href="https://github.com/Azure/aks-engine/blob/v0.42.2/parts/k8s/addons/coredns.yaml#L214-L220" rel="nofollow noreferrer">here</a>.</p>

<p>Another option (#2) could be to add a new configMap with your configuration and that also imports the <code>/etc/coredns/Corefile</code> file mounted as volume from the "stock" <code>coredns</code> configMap; change the <code>coredns</code> <em>deployment</em> configuration to add a volume from the new configMap and point the <a href="https://github.com/Azure/aks-engine/blob/v0.42.2/parts/k8s/addons/coredns.yaml#L166" rel="nofollow noreferrer">"-conf" argument</a> to the file mounted as volume from the new configMap.</p>

<p>A drawback is that in both cases you'll have to re-implement the change if in a later release the coredns configMap and/or deployment configuration change.</p>
