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!
CodePudding user response:
I think you are missing the namespace name.
You can try this:
# 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.demo -O - # check if this works or not
CodePudding user response:
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)