CoreDNS is Rancher’s default DNS component and you want it to return hosts static file results instead of querying upstream DNS servers.
This solves the problem of upstream DNS servers not being able to resolve the queried domain name at all.
Configuring hosts ConfigMap
Under the kube-system namespace, create a new ConfigMap
Modify the contents of
coredns-hosts as appropriate.
Modify the coredns deployment
coredns under the kube-system namespace, mount ConfigMap
/etc/hosts-custom/coredns-hosts in the Pod, and note the
volumes sections below.
Modify CoreDNS configuration
coredns under kube-system namespace, Key
Corefile is its configuration file, add the following 3 lines.
<zone> means the domain name suffix, e.g.
edu.cn then all queries for domains with the suffix
.edu.cn will go to
/etc/hosts-custom/coredns-hosts for answers.
fallthrough is used to set which
<zone>s can be submitted to the upstream DNS server if the answer is not found.
CoreDNS will load the configuration automatically (without rebooting), and it will also load it automatically if you change the hosts file.
Then just go to any Pod and experiment with nslookup.