Saturday, June 4, 2022

[Resolved] default.svc.cluster.local: Name or service not known



After creating a service when I tried to verify if the DNS name for the service is getting resolved or I got the following error. 


 my-service.default.svc: Name or service not known


I was unable to confirm if the service DNS was actually resolving or not and if there was some issue as the service itself was not accessible via curl or the browser

 [[email protected] service]$ nslookup my-service.default.svc  
 -bash: nslookup: command not found  
 [[email protected] service]$ dig nslookup my-service.default.svc  
 -bash: dig: command not found  
 [[email protected] service]$ ping nslookup my-service.default.svc  
 ping: my-service.default.svc: Name or service not known  
 [[email protected] service]$ ping my-service.default.svc  
 ping: my-service.default.svc: Name or service not known  


Follow the following steps

1. Create a pod with the DNS utils installed on it for making the nslookup command work inside the pod
 kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml  

2. Now run the nslookup command on the DNS name and verify if its getting resolved or not
[[email protected] service]$ kubectl exec -it dnsutils -- nslookup my-service.default.svc  
 Name:     my-service.default.svc.cluster.local  


Previously i was trying to resolve the DNS on the host network but the coredns works inside the kubernetes cluster only or pod network not the host network that is why you cannot use the traditional way of resolving the DNS using the nslookup or dig command. So we installed a pod with the dnsutils installed inside it and than we provide the nslookup command from inside the pod and directly print the result on the stdout. So you can use this way to resolve the DNS and verify if its working fine or not. Also you should put till svc as the kubernetes can take the cluster.local itself.


Post a Comment