当前位置:网站首页>Principle of container network
Principle of container network
2022-07-23 14:05:00 【Tang Bohu points mosquito repellent incense DW】
Bridge:
docker adopt docker0 This bridge is used to ensure the communication between containers , But the bridge generally only recognizes mac Address , Do not recognize ip Address , It belongs to layer-2 network equipment , The router belongs to a three-layer network device , We send a package to a ip after , First, the layer 3 network device will broadcast arp Package to inquire about the ip To which the address belongs mac Address , find mac Address will be mac The purpose of writing the address into the network packet mac Address , Then layer-2 network devices can pass mac Address find the corresponding network card, that is , The bridge is usually a two-layer device , It's not ip Address of the , that docker0 It's a virtual bridge , Why set up a ip The address? , This is because you set a ip After the address , It is associated with the kernel protocol stack , In this way, the associated network namespace can be linked to the host , And the public network
veth-pair:
Linux A network device of , This network device has two endpoints , Data enters from an endpoint , It's bound to flow from the other end point , Every veth Can be endowed with ip Address , And participate in the three-layer network routing process. The network equipment is given ip after , Then one end of it can be considered to be connected to the protocol stack
docker After starting a container , Will create a veth-pair network card , One end links docker0, One end links the protocol stack in the container , And create routes for them ( Why do you create routes at both ends )
We created one veth-pair After equipment , We have two network segments at both ends ip, We from ip1 ping To ip2 When , If there is no corresponding routing rule , Then the host will not know which device to send the packet to , After we create a route, the protocol stack knows to send to veth-pair equipment , But after sending vethpair Need destination mac Address , our ip2 received arp After the request , reply mac Address , But the request it replies to doesn't know which device to send , So you also need to create a path matching
docker Communication between containers and with host :
docker The communication between containers is through docker0 This bridge , After starting a container, create a veth-pair equipment , One end links the internal network namespace protocol stack of the container , One end links docker0, such docker0 As a bridge, you can communicate during the period of Derong , If between containers ip Are different network segments , Then you need to configure the routing table , otherwise arp The package cannot find the address and cannot return mac Address , Then how does the internal network namespace of the container communicate with the host , This needs to be docker0 To configure a ip Address to link the network protocol stack of the host , Then you need to add routing rules inside the container , Configure the next hop address as docker0, such docker0 You can forward packets to the host
docker Visit the Internet :
In fact, after the container is linked to the host protocol stack, it can communicate with the host or the external network , But there is a precondition :
1. Run firewall , Routing and forwarding
iptables -A FORWARD -j ACCEPT
2. The kernel allows routing and forwarding , Modify value 1
vim /proc/sys/net/ipv4/ip_forward
3. To configure iptables -t nat -A POSTROUTING -S 192.168.15.0/24 -J MASQUERADE This configuration will 192.168.15.0/24 Address out ip Change the source address of to the gateway address , If you don't replace it, you won't find the network card when you come back
flannel vxlan: Realize the communication between different host containers :
vxlan It's a kind of Linux Network devices on ( It is a layer-2 network device ), This device is able to send packets inside udp Encapsulation , To the outside to achieve vxlan Unpack the package on ,vxlan When the package is received , Will be in fdb In the table, the mac Check the address to be delivered ip Address .
vxlan By looking for fdb To forward the received packets ,
Such as through bridge fdb see
......
00:00:00:00:00:00 dev vxlan0 dst 192.168.64.4 via enp0s1 self permanent
This means any mac Address the package as long as it arrives vxlan0 On this network device , He will be sent to a purpose ip by 192.168.64.4 On this host ,k8s Slightly different
calico It realizes the communication between different hosts by configuring routing rules , His advantage is that there is no unpacking , More efficient

边栏推荐
- Unity makes simple intercepting close range artillery - how to predict the strike target
- MYSQL练习题:向CEO汇报的所有员工
- Tutorial on principles and applications of database system (040) -- MySQL query (II): set the column name or expression to be queried
- Golang remote server debugging
- Image processing 4: corrosion
- 使用Stream流来进行分类展示。
- 配置firecracker流程即踩坑记录
- 中等靶场
- 《乔布斯传》英文原著重点词汇笔记(十五)【 chapter fourteen】
- C #: in, out, ref Keywords
猜你喜欢

赛扬N4000和赛扬N5095的区别

考研题库小程序中如何实现打开考研思维导图pdf

script之type=module

Google Earth engine -- a small bug in gee. Images of transcontinental boundaries cannot be obtained

天玑1100相当于骁龙多少处理器 天玑1100相当于骁龙多少 天玑1100怎么样

子组件向父组件传参的几种方法

静态综合实验(HCIA)

excel随笔记录

Static comprehensive experiment (HCIA)

达人评测 酷睿i9 12950hx和i9 12900hx区别哪个强
随机推荐
中等靶场
iQOO 10 Pro和vivo X80 Pro区别 哪个好详细参数配置对比
酷睿i5 12490f和i5 12600k差距大吗
200 lines of code, in-depth analysis of the principle and implementation of dynamic calculation diagram
OSPF detailed explanation (LSA) (2)
200 行代码,深入分析动态计算图的原理及实现
数据链路层协议,PPP会话
T-SEDA编码
MGRE comprehensive experiment
rtx3080相当于gtx什么显卡 rtx3080显卡什么水平 rtx3080显卡怎么样
Tutorial on principles and applications of database system (038) -- index of MySQL (4): analyze index with explain command
BGP联邦实验
How can Creo 9.0 quickly modify CAD coordinate system?
锐龙R7 PRO 5875U性能怎么样?相当于什么水平级别
iQOO 10 Pro和小米12 Ultra哪个好 哪个值得买 两者配置对比
KingbaseES DENSE_RANK 函数用法
BERT 文章翻译
Image processing 7: test files
七月到底有多热?通过爬虫爬取当月温度信息,并使用matplotlib绘制温度折线图
Image processing 4: corrosion