Cluster information:
Kubernetes version: v1.19
Installation method: kubeadm
Host OS: Ubuntu
CNI : Weave
CRI : Docker
-------------------------------------------------------------------
$ kubectl get po -n hook
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 6s
$ kubectl get po -owide -n hook
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 13s 10.44.0.2 node01 <none> <none>
$ kubectl get po
NAME READY STATUS RESTARTS AGE
test 1/1 Running 0 60s
$ kubectl get po -owide -n hook
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 2m31s 10.44.0.2 node01 <none> <none>
$ kubectl exec -it test -- sh
/ # nslookup 10-44-0-2.default.pod.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 10-44-0-2.default.pod.cluster.local
Address 1: 10.44.0.2
/ # nslookup 10-44-0-2.hook.pod.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 10-44-0-2.hook.pod.cluster.local
Address 1: 10.44.0.2
As per k8s docs DNS for Services and Pods | Kubernetes
In general a pod has the following DNS resolution:
pod-ip-address.my-namespace.pod.cluster-domain.example
.
For example, if a pod in the
default
namespace has the IP address 172.17.0.3, and the domain name for your cluster iscluster.local
, then the Pod has a DNS name:
172-17-0-3.default.pod.cluster.local
.
But in the above scenario, I am able to resolve from default namespace too and again I created a new namespace red. I am able to resolve from that namespace too.
$ kubectl create ns red
namespace/red created
$ kubectl exec -it test -- sh
/ # nslookup 10-44-0-2.red.pod.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 10-44-0-2.red.pod.cluster.local
Address 1: 10.44.0.2
/ #
Any experts can please share their review on this? or am I missing something?