<p>I have ingress-nginx configured with ingress resources that are host specific so how can I access <a href="http://appX.my.example.com" rel="nofollow noreferrer">http://appX.my.example.com</a> both from my desktop browser and also from within other pods inside the cluster, that also need to access <a href="http://appX.my.example.com" rel="nofollow noreferrer">http://appX.my.example.com</a>?</p>
<p>I'm running kubernetes locally using <a href="https://kind.sigs.k8s.io/" rel="nofollow noreferrer">kind</a> in a docker container on windows. I'm guessing the exact same question would apply for minicube, k3s or whatever. I'm running this on Windows with Docker for-win and WSL2 (which may not matter).</p>
<p>One solution that I've found is to see what the IP address <code>host.docker.internal</code> resolves to (currently <code>192.168.1.100</code>) and then create entries like this in <code>C:\Windows\System32\drivers\etc\hosts</code>:</p>
<pre><code>192.168.1.100   appx.my.example.com
192.168.1.100   appy.my.example.com
</code></pre>
<p>Now <a href="http://appX.my.example.com" rel="nofollow noreferrer">http://appX.my.example.com</a> resolves correctly both in the desktop browser and for <code>appY</code>. Everything works. Two problems with this:</p>
<ul>
<li>E.g. after reboots, after starting a VPN and for other black-magic reasons, <code>host.docker.internal</code> changes IP addresses &quot;sometimes&quot;</li>
<li>It is not possible to create a <code>*.my.example.com</code> entry in <code>C:\Windows\System32\drivers\etc\hosts</code> (or linux <code>/etc/hosts</code> either).</li>
</ul>
<p>This leads to a need to maintain the <code>hosts</code> file which is error-prone and annoying.</p>
<p>Is there a better way? What is the easiest way to develop with kubernetes on localhost if we want to use named hosts in ingress rules?</p>

Peter V. Mørch
<p>Here's what I've come up with:</p>
<p>I've created a wildcard certificate in a real DNS entry in a domain I own. Something like</p>
<pre><code>*.local.mydomain.dk. IN A 127.0.0.1
</code></pre>
<p>Now the trick is to get coredns (the DNS server in the kubernetes cluster) to resolve <code>*.local.mydomain.dk</code> to a <code>CNAME host.docker.internal</code>. To do that, I've modified both the configmap and deployment called <code>coredns</code> in the <code>kube-system</code> name space:</p>
<pre><code>diff -u configmap.yaml.orig configmap.yaml
--- configmap.yaml.orig 2021-08-10 00:24:29.234095600 +0200
+++ configmap.yaml  2021-08-10 00:24:37.664095600 +0200
@@ -7,6 +7,7 @@
            lameduck 5s
         }
         ready
+        file /etc/coredns/mydomain.dk.db local.mydomain.dk
         kubernetes cluster.local in-addr.arpa ip6.arpa {
            pods insecure
            fallthrough in-addr.arpa ip6.arpa
@@ -21,6 +22,11 @@
         reload
         loadbalance
     }
+  mydomain.db: |
+    local.mydomain.dk.   IN SOA   sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
+    local.mydomain.dk.   IN NS    a.iana-servers.net.
+    local.mydomain.dk.   IN NS    b.iana-servers.net.
+    *.local.mydomain.dk. IN CNAME host.docker.internal.
 kind: ConfigMap
 metadata:
   creationTimestamp: &quot;2021-08-09T21:58:26Z&quot;
</code></pre>
<pre><code>diff -u deployment.yaml.orig deployment.yaml
--- deployment.yaml.orig    2021-08-10 00:26:17.324095600 +0200
+++ deployment.yaml 2021-08-10 00:25:57.584095600 +0200
@@ -108,6 +108,8 @@
           items:
           - key: Corefile
             path: Corefile
+          - key: mydomain.dk.db
+            path: mydomain.dk.db
           name: coredns
         name: config-volume
 status:
</code></pre>
<p>Now <code>whatever.local.mydomain.dk</code> resolves to <code>127.0.0.1</code> in the browser and to <code>host.docker.internal</code> inside pods. Bingo!</p>
