CoreDNS QPS is positively correlated with the CPU usage. If the QPS is high, adjust the coredns instance specifications based on the QPS.
If the add-on performance reaches the bottleneck, adjust the coredns add-on specifications.
If the domain name resolution failure rate is lower than 1/10000, optimize parameters by referring to How Do I Optimize the Configuration If the External Domain Name Resolution Is Slow or Times Out? or add a retry policy in the service.
When service requests in the cluster are sent to an external DNS server, a domain name resolution error occurs due to occasional UnknownHostException. UnknownHostException is a common exception. When this exception occurs, check whether there is any domain name-related error or whether you have entered a correct domain name.
To locate the fault, perform the following steps:
cat /sys/fs/cgroup/cpu/kubepods/pod<pod_uid>/<coredns container ID>/cpu.stat
kubectl get po <pod name> -nkube-system -ojsonpath='{.metadata.uid}{"\n"}'
In the preceding command, <pod name> indicates the name of the coredns add-on running on the current node.
Docker nodes:
docker ps --no-trunc | grep k8s_coredns | awk '{print $1}'
containerd nodes:
crictl ps --no-trunc | grep k8s_coredns | awk '{print $1}'
Example:
cat /sys/fs/cgroup/cpu/kubepods/pod27f58662-3979-448e-8f57-09b62bd24ea6/6aa98c323f43d689ac47190bc84cf4fadd23bd8dd25307f773df25003ef0eef0/cpu.stat
Pay attention to the following metrics:
If the host name and DNS settings are correct, you can use the following optimization policies.
Optimization policies:
How to modify:
Restart the coredns add-on after you modify the configurations.
How Do I Optimize the Configuration If the External Domain Name Resolution Is Slow or Times Out?
Example:
dnsConfig:
options:
- name: timeout
value: '2'
- name: ndots
value: '5'
- name: single-request-reopen
You are advised to change the value of ndots to 2.