nam
nam

Reputation: 21

Kubernetes - network: pod can access to other pod by IP but not by name. why?

I created a k8s cluster on vmwareworkstation (kubeadm) and now try on networkpolicy lab.

Here is my code:

# create new ns
    kubectl create ns demo 
# run new nginx pod 
    kubectl run nginx -n demo --image nginx 
# expose pod by clusterIP 
    kubectl expose po nginx --port=80 -n demo 
# run busybox to connect to nginx pod
    kubectl run busybox --image busybox -n default --rm -ti /bin/sh
    # busybox is not same namespace with nginx
    wget -q --timeout=5 nginx -O - # return timeout since two pods not in same namespace
    wget -q --timeout=5  -O -10.244.2.21 -O - # it works this time with IP of nginx pod. 

Can somebody explain me what is going on here ? is that everything right with my k8s cluster ?

Thank you so much!

Upvotes: 0

Views: 51

Answers (1)

nam
nam

Reputation: 21

Turn out my problem come from coredns. re-install cluster again with calico plugin -> problem solved.

for the ans: by default, all pod connect to each other by IP not name. Only apply service (ClusterIP) let pod access to each other by service name (eg: Nginx)

Upvotes: 2

Related Questions