Accessing Pod using FQDN of Service

I have a deployment as below where 2 Pods are running on the same NODE and namespace.

I want to access Pod-B from Pod-A **using the"fqdn" of the service** (i.e. svcA in the below example) and **not using nodeIP**.

I ALSO want to access Pod-B from Pod-A **using the"fqdn" of the podB** (i.e. not using IP of pod-B) .

Does k8s provides this option or if there is a need to resolve the FQDN to an IP address? If so, please suggest where to route this to “core-DNS” ?

pod-A (IP:A) ------>svc(name: svcA, IP:nodeIP, port:nodePort) ----->pod-B (IP:B)

K8s uses the internal DNS by default if your tried to hit a pod using any name:
For Ex: Try this
kubectl run pod1 --image=busybox:1.28 --command sleep 4800
kubectl run pod2 --image=busybox:1.28 --command sleep 4800
kubectl expose pod pod1 --port=8080
kubectl expose pod pod2 --port=8080
kubectl get svc

Then exec to any pod using:
kubectl exec pod1 -it /bin/sh

You can then use the command nslookup to search for the service
nslookup pod1

It will return something like this
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: pod1
Address 1: 10.50.192.1 pod1

Note that pod1 in that case is the name of the pod.

If you want to use the fqdn of the service, like discussed in the video, you can use
nslookup pod1.default.svc.cluster.local
or If you don’t remember the full syntax
nslookup pod1.default
It will then return the FQDN as here pod1 is the name of the service. Output should be like
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: pod1.default
Address 1: 10.106.220.147 pod1.default.svc.cluster.local

1 Like

Thank you so much for the detailed and precise answer. I really appreciate that.

1 Like

@debu3645
Happy learning!