064、Weave网络结构分析(2019-04-04 周四)
Weave网络使用之前需要执行 eval $(weave env) ,其作用是将后续的docker 命令发送给weave proxy处理,如果需要恢复之前的网络,可以执行 eval $(weave env --restore)
root@host1:~# eval $(weave env)
root@host1:~# docker run --name bbox1 -itd busybox
c3414fa41f61583a82aeef4dbbe8f4431f01b063a60696f15ccab35ab68b13f7
root@host1:~# docker exec bbox1 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
24: eth0@if25: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue
link/ether 02:42:0a:02:2e:02 brd ff:ff:ff:ff:ff:ff
inet 10.2.46.2/24 brd 10.2.46.255 scope global eth0
valid_lft forever preferred_lft forever
26: ethwe@if27: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1376 qdisc noqueue
link/ether aa:f8:77:29:4e:49 brd ff:ff:ff:ff:ff:ff
inet 10.32.0.1/12 brd 10.47.255.255 scope global ethwe
valid_lft forever preferred_lft forever
root@host1:~# ip link
27: vethwepl3962@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue master weave state UP mode DEFAULT group default
link/ether 3e:45:bc:fd:67:82 brd ff:ff:ff:ff:ff:ff link-netnsid 0
root@host1:~# brctl show
bridge name bridge id STP enabled interfaces
docker0 8000.0242fbab05c3 no vetha0c66cd
weave 8000.9aac0ef31a18 no vethwe-bridge
vethwepl3962
# bbox1中的 ethwe@if27 与 host 上的 vethwe13962@if26 是一对 veth pair , vethwep13962 又挂在了桥 weave下面
root@host1:~# ip -d link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 addrgenmode eui64
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:50:56:87:4c:70 brd ff:ff:ff:ff:ff:ff promiscuity 0 addrgenmode eui64
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:50:56:87:22:32 brd ff:ff:ff:ff:ff:ff promiscuity 0 addrgenmode eui64
4: ens192.10@ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 00:50:56:87:22:32 brd ff:ff:ff:ff:ff:ff promiscuity 0
vlan protocol 802.1Q id 10 <REORDER_HDR> addrgenmode eui64
5: ens192.20@ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 00:50:56:87:22:32 brd ff:ff:ff:ff:ff:ff promiscuity 0
vlan protocol 802.1Q id 20 <REORDER_HDR> addrgenmode eui64
6: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN mode DEFAULT group default
link/ether 66:2b:a5:56:0d:c6 brd ff:ff:ff:ff:ff:ff promiscuity 0
vxlan id 1 local 10.12.31.211 dev ens160 srcport 0 0 dstport 8472 nolearning ageing 300 addrgenmode eui64
7: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
link/ether 02:42:fb:ab:05:c3 brd ff:ff:ff:ff:ff:ff promiscuity 0
bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time 30000 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q addrgenmode eui64
16: datapath: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
link/ether 0e:46:0b:d9:e7:46 brd ff:ff:ff:ff:ff:ff promiscuity 1
openvswitch addrgenmode eui64
18: weave: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 9a:ac:0e:f3:1a:18 brd ff:ff:ff:ff:ff:ff promiscuity 0
bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time 30000 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q addrgenmode eui64
19: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 76:8c:4e:05:d9:24 brd ff:ff:ff:ff:ff:ff promiscuity 0
dummy addrgenmode eui64
21: vethwe-datapath@vethwe-bridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue master datapath state UP mode DEFAULT group default
link/ether be:d6:9a:e2:7c:cb brd ff:ff:ff:ff:ff:ff promiscuity 1
veth
openvswitch_slave addrgenmode eui64
22: vethwe-bridge@vethwe-datapath: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue master weave state UP mode DEFAULT group default
link/ether e2:ad:6d:b8:8d:c4 brd ff:ff:ff:ff:ff:ff promiscuity 1
veth
bridge_slave state forwarding priority 32 cost 2 hairpin off guard off root_block off fastleave off learning on flood on addrgenmode eui64
23: vxlan-6784: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master datapath state UNKNOWN mode DEFAULT group default qlen 1000
link/ether da:4e:f2:ed:84:34 brd ff:ff:ff:ff:ff:ff promiscuity 1
vxlan id 0 srcport 0 0 dstport 6784 nolearning ageing 300 udp6zerocsumrx
openvswitch_slave addrgenmode eui64
25: vetha0c66cd@if24: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP mode DEFAULT group default
link/ether 0a:ea:26:d8:40:3c brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 1
veth
bridge_slave state forwarding priority 32 cost 2 hairpin off guard off root_block off fastleave off learning on flood on addrgenmode eui64
27: vethwepl3962@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1376 qdisc noqueue master weave state UP mode DEFAULT group default
link/ether 3e:45:bc:fd:67:82 brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 1
veth
bridge_slave state forwarding priority 32 cost 2 hairpin on guard off root_block off fastleave off learning on flood on addrgenmode eui64
# 1、vethwe-bridge@vethwe-datapath 和 vethwe-datapath@vethwe-bridge 是一对 veth pair
# 2、vethwe-datapath 的父设备(master)是datapath
# 3、datapath是一个openvswitch
# 4、vxlan-6784 是vxlan interface ,其master也是datapath,weave主机间通信走的是vxlan
root@host1:~# docker run --name bbox2 -itd busybox
8ba1a2fd0b8142460adce5c0c84f340f1293c70725703f7553b8eb8f3b559a9b
root@host1:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ba1a2fd0b81 busybox "/w/w sh" 7 seconds ago Up 5 seconds bbox2
c3414fa41f61 busybox "/w/w sh" 7 minutes ago Up 7 minutes bbox1
7e8598656934 weaveworks/weave:2.5.1 "/home/weave/weaver …" 25 hours ago Up 25 hours weave
65fab63189a6 weaveworks/weaveexec:2.5.1 "data-only" 25 hours ago Created weavevolumes-2.5.1
a4d5d7b88819 weaveworks/weavedb:latest "data-only" 25 hours ago Created weavedb
root@host1:~# docker exec bbox1 hostname
bbox1.weave.local
root@host1:~# docker exec bbox2 hostname
bbox2.weave.local
root@host1:~# docker exec bbox1 ping bbox2
PING bbox2 (10.32.0.2): 56 data bytes
64 bytes from 10.32.0.2: seq=0 ttl=64 time=0.097 ms
64 bytes from 10.32.0.2: seq=1 ttl=64 time=0.041 ms
64 bytes from 10.32.0.2: seq=2 ttl=64 time=0.076 ms
root@host1:~# docker exec bbox1 ip r
default via 10.2.46.1 dev eth0
10.2.46.0/24 dev eth0 scope link src 10.2.46.2
10.32.0.0/12 dev ethwe scope link src 10.32.0.1
224.0.0.0/4 dev ethwe scope link
root@host1:~# docker exec bbox2 ip r
default via 10.2.46.1 dev eth0
10.2.46.0/24 dev eth0 scope link src 10.2.46.3
10.32.0.0/12 dev ethwe scope link src 10.32.0.2
224.0.0.0/4 dev ethwe scope link
weave网络拓扑如下