I ping kubernetes pod ip from host,it success. So what is the procedure about it? I read many to talk pod to pod communication,but nothing about host to pod. According my knownlege, The kubernetes cluster is individual about host machine and communication through edge nodes ingress controller.I am confusing about this.
In fact this is Docker's behaviour, not Kubernetes (supposing you're using Docker as your container runtime).
By default, when you install Docker, there is a default network interface that is created on your host : docker0 (you should be able to see it with ifconfig
). This interface is an ethernet bridge device.
So as stated in the documentation :
If you don’t specify a different network when starting a container, the container is connected to the bridge and all traffic coming from and going to the container flows over the bridge to the Docker daemon, which handles routing on behalf of the container.
This is why you can ping your container from your host.
If you want to customize default IP range for this interface, you can refer to the official documentation
The normal behavior of Kubernetes is that the Kubernetes cluster has its own isolated network infrastructure. You can't normally directly access the pod (or service) IP addresses from outside Kubernetes space, even from a shell on the same physical host. As @MarcAbouchacra points out it might be possible in some desktop-based Kubernetes setups, but it usually doesn't work.
If you need to access Kubernetes pods, you almost always need to set up a service in front of them, whether the call is coming from inside the cluster or outside. You don't normally access individual pods. If you want the service to be accessible from outside the cluster (including from the same physical host) you need to change the service type; in this sort of desktop environment a NodePort
service will allocate a port on the host that can reach the service.
For testing purposes only you can kubectl port-forward
a host port to a specific container port, but this doesn't work well for high-volume traffic or long-lived connections (it is not a substitute for setting up a service). Also for testing purposes, you can kubectl run
a debugging pod with an interactive shell and run commands like curl
from there.