Can't resolve dns from inside k8s pod

7/27/2020

In dnsutils pod exec ping stackoverflow.com

/ # ping stackoverflow.com
ping: bad address 'stackoverflow.com'

The /etc/resolve.conf file looks fine from inside the pod

/ # cat /etc/resolv.conf 
nameserver 10.96.0.10
search weika.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

10.96.0.10 is the kube-dns service ip:

[root@test3 k8s]# kubectl -n kube-system get service
NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                     AGE
kube-dns                    ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP      75d

core dns

[root@test3 k8s]# kubectl -n kube-system get  pod -o wide | grep core
coredns-6557d7f7d6-5nkv7                             1/1     Running   0          10d   10.244.0.14    test3.weikayuninternal.com   <none>           <none>
coredns-6557d7f7d6-gtrgc                             1/1     Running   0          10d   10.244.0.13    test3.weikayuninternal.com   <none>           <none>

when I change the nameserver ip to coredns ip. resolve dns is ok.

/ # cat /etc/resolv.conf 
nameserver 10.244.0.14
#nameserver 10.96.0.10
search weika.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
/ # ping stackoverflow.com
PING stackoverflow.com (151.101.65.69): 56 data bytes
64 bytes from 151.101.65.69: seq=0 ttl=49 time=100.497 ms
64 bytes from 151.101.65.69: seq=1 ttl=49 time=101.014 ms
64 bytes from 151.101.65.69: seq=2 ttl=49 time=100.462 ms
64 bytes from 151.101.65.69: seq=3 ttl=49 time=101.465 ms
64 bytes from 151.101.65.69: seq=4 ttl=49 time=100.318 ms
^C
--- stackoverflow.com ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 100.318/100.751/101.465 ms
/ # 

Why is it happening?

-- Minato
dns
kube-dns
kubernetes

1 Answer

7/27/2020

You have not mentioned how kubernetes was installed. You should restart coredns pods using below command.

kubectl -n kube-system rollout restart deployment coredns
-- Arghya Sadhu
Source: StackOverflow