负载均衡定义
负载均衡器的实现原理是通过硬件或软件设备将客户端访问流量根据转发策略分发到多个服务器或设备上,以确保系统的负载均衡。常见的实现方式包括:
- 二层负载均衡:使用虚拟MAC地址方式,根据OSI模型的二层进行负载均衡。
- 四层负载均衡:基于IP+端口的负载均衡,主要分析IP层及TCP/UDP层,实现四层负载均衡。
- 七层负载均衡:从应用层开始,根据虚拟的URL或IP、主机名接收请求,再转向相应的处理服务器。
二层负载均衡
- 网络设备:交换机
- 过程分析:只有当pod访问负载均衡vip且是首包的情况下匹配switch负载均衡,在group里采用select机制根据数据包五元组哈希选择一个endpoint,打上ct_mark标记,并dnat到endpoint
- ovs流表:
table=19, priority=120,ct_state=+new+trk,tcp,metadata=0x1,nw_dst=10.96.187.144,tp_dst=10001 actions=load:0->NXM_NX_XXREG0[97],load:0xa60bb90→NXM_NX_XXREG0[64..95],load:0x2711→NXM_NX_XXREG0[32..47],group:5
# 在group里进行负载均衡
group_id=5,type=select,selection_method=dp_hash,bucket=bucket_id:0,weight:100,actions=ct(commit,table=20,zone=NXM_NX_REG13[0..15],nat(dst=10.244.0.4:80),exec(load:0x1->NXM_NX_CT_MARK[1])),bucket=bucket_id:1,weight:100,actions=ct(commit,table=20,zone=NXM_NX_REG13[0..15],nat(dst=10.244.0.5:80),exec(load:0x1->NXM_NX_CT_MARK[1])),bucket=bucket_id:2,weight:100,actions=ct(commit,table=20,zone=NXM_NX_REG13[0..15],nat(dst=10.244.0.6:80),exec(load:0x1->NXM_NX_CT_MARK[1])),bucket=bucket_id:3,weight:100,actions=ct(commit,table=20,zone=NXM_NX_REG13[0..15],nat(dst=10.244.0.7:80),exec(load:0x1→NXM_NX_CT_MARK[1]))
- ovn流表:
# ovn-trace --ct=new node1 'inport=="ovn-poc_service-a-89c68dc96-f75t2" && eth.src== 0a:58:0a:f4:00:04 && eth.dst == 0a:58:0a:f4:00:01 && ip4.src==10.244.0.4 && ip.ttl==64 && ip4.dst==10.96.187.144 && tcp.dst==10001'
# tcp,reg14=0x3,vlan_tci=0x0000,dl_src=0a:58:0a:f4:00:04,dl_dst=0a:58:0a:f4:00:01,nw_src=10.244.0.4,nw_dst=10.96.187.144,nw_tos=0,nw_ecn=0,nw_ttl=64,tp_src=0,tp_dst=10001,tcp_flags=0
ingress(dp="node1", inport="ovn-poc_service-a-89c68dc96-f75t2")
---------------------------------------------------------------
0. ls_in_check_port_sec (northd.c:7727): 1, priority 50, uuid 03dc908c
reg0[15] = check_in_port_sec();
next;
4. ls_in_pre_acl (northd.c:5649): ip, priority 100, uuid df97729f
reg0[0] = 1;
next;
5. ls_in_pre_lb (northd.c:5820): ip, priority 100, uuid 1990086a
reg0[2] = 1;
next;
6. ls_in_pre_stateful (northd.c:5852): reg0[2] == 1 && ip4 && tcp, priority 120, uuid 454a1f78
reg1 = ip4.dst;
reg2[0..15] = tcp.dst;
ct_lb_mark;
ct_lb_mark
----------
7. ls_in_acl_hint (northd.c:5929): ct.new && !ct.est, priority 7, uuid 24ab3fd0
reg0[7] = 1;
reg0[9] = 1;
next;
8. ls_in_acl (northd.c:6545): ip && !ct.est, priority 1, uuid 8eaca776
reg0[1] = 1;
next;
11. ls_in_lb (northd.c:6858): ct.new && ip4.dst == 10.96.187.144 && tcp.dst == 10001, priority 120, uuid 4bf79ca8
reg0[1] = 0;
reg1 = 10.96.187.144;
reg2[0..15] = 10001;
ct_lb_mark(backends=10.244.0.4:80,10.244.0.5:80,10.244.0.6:80,10.244.0.7:80);
ct_lb_mark /* default (use --ct to customize) */
------------------------------------------------
14. ls_in_pre_hairpin (northd.c:6931): ip && ct.trk, priority 100, uuid 1328c195
reg0[6] = chk_lb_hairpin();
reg0[12] = chk_lb_hairpin_reply();
*** chk_lb_hairpin_reply action not implemented
next;
23. ls_in_l2_lkup (northd.c:8465): eth.dst == 0a:58:0a:f4:00:01, priority 50, uuid 3c5ecd19
outport = "stor-node1";
output;
egress(dp="node1", inport="ovn-poc_service-a-89c68dc96-f75t2", outport="stor-node1")
------------------------------------------------------------------------------------
0. ls_out_pre_lb (northd.c:5538): ip && outport == "stor-node1", priority 110, uuid 2d693c30
next;
1. ls_out_pre_acl (northd.c:5538): ip && outport == "stor-node1", priority 110, uuid c384472d
next;
3. ls_out_acl_hint (northd.c:5992): ct.est && ct_mark.blocked == 0, priority 1, uuid f77da843
reg0[10] = 1;
next;
8. ls_out_check_port_sec (northd.c:5505): 1, priority 0, uuid 4fb4d39f
reg0[15] = check_out_port_sec();
next;
9. ls_out_apply_port_sec (northd.c:5510): 1, priority 0, uuid 6d6e8323
output;
/* output to "stor-node1", type "patch" */
ingress(dp="ovn_cluster_router", inport="rtos-node1")
-----------------------------------------------------
0. lr_in_admission (northd.c:10835): eth.dst == 0a:58:0a:f4:00:01 && inport == "rtos-node1" && is_chassis_resident("cr-rtos-node1"), priority 50, uuid be29772f
xreg0[0..47] = 0a:58:0a:f4:00:01;
next;
1. lr_in_lookup_neighbor (northd.c:10979): 1, priority 0, uuid e1a8324c
reg9[2] = 1;
next;
4378



被折叠的 条评论
为什么被折叠?



