skip to content
Alvin Lucillo

Add DNS resolution for new domain

/ 1 min read

For example, if you want to add cka.local in your cluster DNS resolution in the same level as cluster.local, edit the coredns configmap. Look for the Corefile definition and add cka.local. It’s

k edit cm coredns -n kube-system
configmap/coredns edited


apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        ready
        kubernetes cluster.local cka.local in-addr.arpa ip6.arpa { # add here
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        hosts /etc/coredns/NodeHosts {
          ttl 60
          reload 15s
          fallthrough
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
        import /etc/coredns/custom/*.override
    }
    import /etc/coredns/custom/*.server
  NodeHosts: |
    192.168.140.138 cluster3-controlplane

Restart coredns deployment and check the pods associated to it:

kubectl -n kube-system rollout restart deployment coredns
kubectl -n kube-system get pods -l k8s-app=kube-dns

Using a pod with jrecord/netools image, try to do nslookup. We can see that the DNS is resolved. Notice that the server is the same for cka.local and cluster.local

 kubectl run dns-test --image=jrecord/nettools --restart=Never -it -- /bin/sh

If you don't see a command prompt, try pressing enter.
sh-4.4#
sh-4.4# nslookup kubernetes.default.svc.cluster.local
Server:         10.43.0.10
Address:        10.43.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.43.0.1

sh-4.4# nslookup kubernetes.default.svc.cka.local
Server:         10.43.0.10
Address:        10.43.0.10#53

Name:   kubernetes.default.svc.cka.local
Address: 10.43.0.1