The network inside Kubernetes is not much different from the network in the physical world. With the basic knowledge of network, you can easily achieve communication between container Pods and services. Moving from physical networks using switches, routers, and Ethernet cables to virtual networks using software-defined networking (SDN) and virtual interfaces requires a slight learning curve. The principles remain the same, of course, but there are different norms and best practices. Kubernetes has its own set of rules, and if you're dealing with containers and clouds, it helps to understand how Kubernetes networking works. The Kubernetes networking model has some general rules to remember:
What problems does Kubernetes networking solve?Kubernetes networking is designed to ensure that different entity types in Kubernetes can communicate. The layout of the Kubernetes infrastructure has a lot of separation by design. Namespaces, containers, and Pods are designed to keep components distinct from each other, so a highly structured communication plan is very important. Container-to-container networkingContainer-to-container networking happens through Pod network namespaces. Network namespaces allow you to have independent network interfaces and routing tables that are isolated and run independently from the rest of the system. Each Pod has its own network namespace, and the containers within it share the same IP address and ports. All communication between these containers happens through localhost because they are all part of the same namespace. (Represented by the green line in the diagram.) Pod-to-Pod Networking With Kubernetes, each node has a designated CIDR IP range for Pods. This ensures that each Pod receives a unique IP address that can be seen by other Pods in the cluster. When creating new Pods, IP addresses never overlap. Unlike container-to-container networking, Pod-to-Pod communication occurs using real IPs, regardless of whether you deploy the Pods on the same node or on different nodes in the cluster. The above diagram shows that in order for Pods to communicate with each other, traffic must flow between the Pod network namespace and the root network namespace. This is achieved by connecting the Pod namespace and the root namespace via a virtual Ethernet device or veth pair (veth0 to Pod namespace 1, veth1 to Pod namespace 2 in the diagram). A virtual bridge connects these virtual interfaces, allowing communication to flow between them using the Address Resolution Protocol (ARP). When data is sent from Pod 1 to Pod 2, the event flow is:
Pod to Service NetworkPods are dynamic. They may need to scale up or down based on demand. They may be created again in case of application crashes or node failures. These events cause the IP address of the Pod to change, which will create challenges for networking. Kubernetes solves this problem by using the Service feature, which does the following:
There are two ways to load balance within a cluster:
The above diagram shows the flow of packets from Pod 1 to Pod 3 through the Service to different nodes (marked in red). Packets heading to the virtual bridge must use the default route (eth0) because the ARP running on the bridge does not understand the service. After that, the packets must be filtered through iptables, which uses the rules defined in the node by the kube-agent. Therefore, the diagram shows the current path. Internet to the service networkSo far, we have discussed how to route traffic within the cluster. However, there is another side to Kubernetes networking, which is exposing applications to the external network. You can expose your application to the external network in two different ways.
Discovery ServicesKubernetes discovers services in two ways:
ServiceTypes for published services A Kubernetes Service provides a way to access a set of Pods, typically defined by using a label selector. This might be an application trying to access other applications in the cluster, or it might allow you to expose applications running in the cluster to the outside world. The different ServiceTypes include:
Network softwareAs long as you understand the technologies used, networking inside Kubernetes is not much different from networking in the physical world. Learn and remember the basics of networking, and you can easily achieve communication between containers, Pods, and services. |
<<: 5G and the Future of Commercial Security Surveillance
1. Introduction Hello everyone, I am Xiao❤, a 985...
HostTheBest's website about page introduces t...
FlipperHost is a foreign hosting company founded ...
Is there a charge for caller ID? This charging it...
The tribe once shared information about UCloud, U...
A recent report released by Research And Markets ...
With the upcoming decommissioning of 2G/3G networ...
During MWC22 Barcelona, Huawei, with the theme ...
PacificRack is a site under QN Data Center, mainl...
1. Introduction frp is a high-performance reverse...
The virtualization characteristics of 5G networks...
On November 28, 2019, in order to accelerate the ...
[[420845]] On August 31, the 2021 World 5G Confer...
HostKvm is a foreign VPS service provider founded...
At present, we are in the Internet era, and Inter...