305-998-7702 | 415-800-2922 info@rx-m.com

Service Discovery with CoreDNS

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

Kubernetes uses CoreDNS for DNS-based service discovery. CoreDNS is flexible and changes can be made in the ConfigMap for CoreDNS.
 
Every Service is assigned with a DNS name in the syntax: <service-name>.<namespace>.svc.cluster.local.
 
Pods are assigned a DNS A record in the syntax of: <pod-hyphen-separated-ip>.<namespace>.pod.cluster.local.
 
Let’s confirm the DNS entry of a service with a name server lookup with nslookup from within a pod.
 
Create a ClusterIP Service to test its DNS entry and retrieve it’s ClusterIP:

$ kubectl create service clusterip my-service --tcp=8080:8080

service/my-service created

$ kubectl get service

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes         ClusterIP   10.96.0.1                           443/TCP        10d
my-service         ClusterIP   10.109.165.220                 8080/TCP       5m31s

$

Run a pod with the busybox image and run a nslookup on the Service’s IP:

$ kubectl run busybox --image=busybox -it -- /bin/sh

If you don’t see a command prompt, try pressing enter.
/ # nslookup 10.109.165.220

Server:		10.96.0.10
Address:	10.96.0.10:53

220.165.109.10.in-addr.arpa	name = my-service.default.svc.cluster.local

/ # exit

$

Learn more about: