Kubernetes assigns the domain name for the pod as <IP address>.<Namespace name>.pod.cluster.local. Because it uses the pod's IP address, FQDN is not guaranteed to be present permanently, but it is nice to have in case an application needs FQDN.
Let's deploy apache2 (httpd) on chap8-domain1 and chap8-domain2, as follows:
$ kubectl run my-apache --image=httpd --namespace chap8-domain1
deployment "my-apache" created
$ kubectl run my-apache --image=httpd --namespace chap8-domain2
deployment "my-apache" created
Type kubectl get pod -o wide to capture an IP address for those pods:
$ kubectl get pods -o wide --namespace=chap8-domain1
NAME READY STATUS RESTARTS AGE IP NODE
my-apache-55fb679f49-qw58f 1/1 Running 0 27s 172.17.0.4 minikube
$ kubectl get pods -o wide --namespace=chap8-domain2
NAME READY STATUS RESTARTS AGE IP NODE
my-apache-55fb679f49-z9gsr 1/1 Running 0 26s 172.17.0.5 minikube
This shows that my-apache-55fb679f49-qw58f on chap8-domain1 uses 172.17.0.4. On the other hand, my-apache-55fb679f49-z9gsr on chap8-domain2 uses 172.17.0.5.
In this case, the FQDN would be:
-
172-17-0-4.chap8-domain1.pod.cluster.local (chap8-domain1)
-
172-17-0-5.chap8-domain2.pod.cluster.local (chap8-domain2)
To check whether name resolution works or not, launch the busybox pod in the foreground (using the -it option). Then use the nslookup command to resolve FQDN to the IP address, as in the following steps:
- Run busybox with the -it option:
$ kubectl run -it busybox --restart=Never --image=busybox
- In the busybox pod, type nslookup to resolve the FQDN of apache on chap8-domain1:
# nslookup 172-17-0-4.chap8-domain1.pod.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 172-17-0-4.chap8-domain1.pod.cluster.local
Address 1: 172.17.0.4
- Also, type nslookup to resolve the FQDN of apache on chap8-domain2:
# nslookup 172-17-0-5.chap8-domain2.pod.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 172-17-0-5.chap8-domain2.pod.cluster.local
Address 1: 172.17.0.5
- Exit the busybox pod, then delete it to release a resource:
# exit
$ kubectl delete pod busybox
pod "busybox" deleted