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 coredns-hosts
.
Modify the contents of coredns-hosts
as appropriate.
Modify the coredns deployment
Modify Deployment coredns
under the kube-system namespace, mount ConfigMap coredns-hosts
to /etc/hosts-custom/coredns-hosts
in the Pod, and note the volumeMounts
and volumes
sections below.
|
|
Modify CoreDNS configuration
Modify ConfigMap coredns
under kube-system namespace, Key Corefile
is its configuration file, add the following 3 lines.
The above <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.
Loading configuration
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.