<p>I am using a baremetal cluster of 1 master and 2 nodes on premise in my home lab with istio, metallb and calico.</p>
<p>I want to create a DNS server in kubernetes that translates IPs for the hosts on the LAN.</p>
<p>Is it possible to use the coreDNS already installed in k8s?</p>

<p>Yes, it's possible but there are some points to consider when doing that. Most of them are described in the Stackoverflow answer below:</p>
<ul>
<li><em><a href="https://stackoverflow.com/questions/55834721/how-to-expose-kubernetes-dns-externally">Stackoverflow.com: Questions: How to expose Kubernetes DNS externally</a></em></li>
</ul>
<p>For example: The DNS server would be resolving the queries that are internal to the Kubernetes cluster (like <code>nslookup kubernetes.default.svc.cluster.local</code>).</p>
<hr />
<p>I've included the example on how you can expose your <code>CoreDNS</code> to external sources and add a <code>Service</code> that would be pointing to some IP address</p>
<p>Steps:</p>
<ul>
<li>Modify the <code>CoreDNS</code> <code>Service</code> to be available outside.</li>
<li>Modify the <code>configMap</code> of your <code>CoreDNS</code> accordingly to:
<ul>
<li><em><a href="https://coredns.io/plugins/k8s_external/" rel="nofollow noreferrer">CoreDNS.io: Plugins: K8s_external</a></em></li>
</ul>
</li>
<li>Create a <code>Service</code> that is pointing to external device.</li>
<li>Test</li>
</ul>
<hr />
<h3>Modify the <code>CoreDNS</code> <code>Service</code> to be available outside.</h3>
<p>As you are new to Kubernetes you are probably aware on how <code>Services</code> work and which can be made available outside. You will need to change your <code>CoreDNS</code> <code>Service</code> from <code>ClusterIP</code> to either <code>NodePort</code> or <code>LoadBalancer</code> (I'd reckon <code>LoadBalancer</code> would be a better idea considering the <code>metallb</code> is used and you will access the <code>DNS</code> server on a port: <code>53</code>)</p>
<ul>
<li><code>$ kubectl edit --namespace=kube-system service/coredns </code> (or <code>kube-dns</code>)</li>
</ul>
<blockquote>
<p>A side note!</p>
<p><code>CoreDNS</code> is using <code>TCP</code> and <code>UDP</code> simultaneously, it could be an issue when creating a <code>LoadBalancer</code>. Here you can find more information on it:</p>
<ul>
<li><a href="https://metallb.universe.tf/usage/" rel="nofollow noreferrer">Metallb.universe.tf: Usage</a> (at the bottom)</li>
</ul>
</blockquote>
<hr />
<h3>Modify the <code>configMap</code> of your <code>CoreDNS</code></h3>
<p>If you would like to resolve domain like for example: <code>example.org</code> you will need to edit the <code>configMap</code> of <code>CoreDNS</code> in a following way:</p>
<ul>
<li><code>$ kubectl edit configmap --namespace=kube-system coredns</code></li>
</ul>
<p>Add the line to the <code>Corefile</code>:</p>
<pre><code>        k8s_external example.org
</code></pre>
<blockquote>
<p>This plugin allows an additional zone to resolve the external IP address(es) of a Kubernetes service. This plugin is only useful if the kubernetes plugin is also loaded.</p>
<p>The plugin uses an external zone to resolve in-cluster IP addresses. It only handles queries for A, AAAA and SRV records; all others result in NODATA responses. To make it a proper DNS zone, it handles SOA and NS queries for the apex of the zone.</p>
<p>-- <em><a href="https://coredns.io/plugins/k8s_external/" rel="nofollow noreferrer">CoreDNS.io: Plugins: K8s_external</a></em></p>
</blockquote>
<hr />
<h3>Create a <code>Service</code> that is pointing to external device.</h3>
<p>Following on the link that I've included, you can now create a <code>Service</code> that will point to an IP address:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
 name: test
 namespace: default
spec:
 clusterIP: None
 externalIPs:
 - 192.168.200.123
 type: ClusterIP
</code></pre>
<hr />
<h3>Test</h3>
<p>I've used <code>minikube</code> with <code>--driver=docker</code> (with <code>NodePort</code>) but I'd reckon your can use the <code>ExternalIP</code> of your <code>LoadBalancer</code> to check it:</p>
<ul>
<li><code>dig @192.168.49.2 test.default.example.org -p 32261 +short</code></li>
</ul>
<pre class="lang-sh prettyprint-override"><code>192.168.200.123
</code></pre>
<p>where:</p>
<ul>
<li><code>@192.168.49.2</code> - IP address of <code>minikube</code></li>
<li><code>test.default.example.org</code> - service-name.namespace.k8s_external_domain</li>
<li><code>-p 32261</code> - <code>NodePort</code> port</li>
<li><code>+short</code> - to limit the output</li>
</ul>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://linux.die.net/man/1/dig" rel="nofollow noreferrer">Linux.die.net: Man: Dig</a></em></li>
</ul>
