Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

We are going to be adding a host alias for example.com in this example by adding the following to the coredns configmap:

Code Block
		hosts custom.hosts example.com {
            1.2.3.4 example.com
            fallthrough
        }


For multiple hosts

Code Block
       hosts custom.hosts example.com test.com {
            1.2.3.4 example.com
            6.6.6.6 test.com
            fallthrough
        }



Start by editing the coredns configmap:

Code Block
languagebash
themeEmacs
kubectl -n kube-system edit configmap/coredns



Code Block
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
           lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :9153
        forward . /etc/resolv.conf {
           max_concurrent 1000
        }
        cache 30
        loop
        reload
        loadbalance
        hosts custom.hosts example.com test.com {
            1.2.3.4 example.com
            6.6.6.6 test.com
            fallthrough
        }
    }


Force CoreDNS to reload the ConfigMap by entering:

Code Block
languagebash
themeEmacs
kubectl delete pod --namespace kube-system -l k8s-app=kube-dns


Performing an nslookup from a pod should show the new IP address for example.com


Code Block
root@ssh-server-5bd5774cf7-fgvt4:/# nslookup example.com
Server:		10.96.0.10
Address:	10.96.0.10#53

Name:	example.com
Address: 1.2.3.4

References

Code Block
apiVersion: v1
kind: ConfigMap
metadata:  
  name: coredns-custom  
  namespace: kube-system 
data:
  example.server: | # All custom server files must have a ".server" file extension. 
    # Change example.com to the domain you wish to forward.
    example.com {
      # Change 1.1.1.1 to your customer DNS resolver.
      forward . 1.1.1.1
    }

Create the ConfigMap by entering:

kubectl apply -f <filename>.yaml

Verify the customizations have been applied by entering:

kubectl get configmaps --namespace=kube-system coredns-custom -o yaml

Force CoreDNS to reload the ConfigMap by entering:

kubectl delete pod --namespace kube-system -l k8s-app=kube-dns

References

...