How to create "DNS entries" for localhost kubernetes ingress hosts?
Here's what I've come up with:
I've created a wildcard certificate in a real DNS entry in a domain I own. Something like
*.local.mydomain.dk. IN A 127.0.0.1
Now the trick is to get coredns (the DNS server in the kubernetes cluster) to resolve *.local.mydomain.dk
to a CNAME host.docker.internal
. To do that, I've modified both the configmap and deployment called coredns
in the kube-system
name space:
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: "2021-08-09T21:58:26Z"
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:
Now whatever.local.mydomain.dk
resolves to 127.0.0.1
in the browser and to host.docker.internal
inside pods. Bingo!