您的位置:首页 > 运维架构 > Docker

play with docker multi-host networking

2017-12-29 09:52 239 查看
使用ovs tunnel组建docker multi-host netwrork记录

分别在两台机器上安装docker,分别为node1, node2

在node1 上创建两个container

docker run --net=mybr  --name=c1 -d -ti busybox sh

docker run --net=mybr  --name=c2 -d -ti busybox sh

在node2上创建一个container:

docker run --net=mybr  --name=c1 -d -ti busybox sh

因为默认情况下docker分配的地址都是从172.17.0.2开始,需要将node1上的c1关闭,

这样避免了地址冲突

docker stop c1

在node1,node2上创建ovs-switch以及gre接口:

ubuntu@docker-node2:~$ ovs-vsctl add-br br-int
ubuntu@docker-node2:~$ sudo ip link add veth0 type veth peer name veth1
ubuntu@docker-node2:~$ sudo ovs-vsctl add-port br-int veth1
ubuntu@docker-node2:~$ sudo brctl addif docker0 veth0
ubuntu@docker-node2:~$ sudo ip link set veth1 up
ubuntu@docker-node2:~$ sudo ip link set veth0 up

在node1上添加gre接口,node1, node2 ip分别为192.168.8.81, 192.168.8.82

ovs-vsctl add-port br-int gre0 -- \
set interface gre0 type=gre options:remote_ip=192.168.8.82
在node2上配置gre:
ovs-vsctl add-port br-int gre0 -- \
set interface gre0 type=gre options:remote_ip=192.168.8.81

验证联通性:
docker exec -ti sh
/ # ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3): 56 data bytes
64 bytes from 172.17.0.3: seq=0 ttl=64 time=1.009 ms
^C
--- 172.17.0.3 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 1.009/1.009/1.009 ms
在node1上抓包:
root@docker-node1:~# tcpdump -n -i eth0 proto gre
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
14:34:21.514041 IP 192.168.8.82 > 192.168.8.81: GREv0, length 102: IP 172.17.0.2 > 172.17.0.3: ICMP echo request, id 3072, seq 0, length 64
14:34:21.515404 IP 192.168.8.81 > 192.168.8.82: GREv0, length 102: IP 172.17.0.3 > 172.17.0.2: ICMP echo reply, id 3072, seq 0, length 64
14:34:22.513888 IP 192.168.8.82 > 192.168.8.81: GREv0, length 102: IP 172.17.0.2 > 172.17.0.3: ICMP echo request, id 3072, seq 1, length 64
14:34:22.514560 IP 192.168.8.81 > 192.168.8.82: GREv0, length 102: IP 172.17.0.3 > 172.17.0.2: ICMP echo reply, id 3072, seq 1, length 64
14:34:23.513956 IP 192.168.8.82 > 192.168.8.81: GREv0, length 102: IP 172.17.0.2 > 172.17.0.3: ICMP echo request, id 3072, seq 2, length 64
14:34:23.514577 IP 192.168.8.81 > 192.168.8.82: GREv0, length 102: IP 172.17.0.3 > 172.17.0.2: ICMP echo reply, id 3072, seq 2, length 64


参考
http://docker-k8s-lab.readthedocs.io/en/latest/index.html http://chunqi.li/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: