用openvswitch创建docker容器之间的vxlan网络

来源:互联网 发布:日本女朋友体验 知乎 编辑:程序博客网 时间:2024/05/16 23:56

环境:

host1 : rhel7.2

host2:     rhel7.2

1)启动docker,导入imag

# systemctl startdocker

# systemctl enabledocker

# docker load -irhel_img.tar

2创建网桥并给ip

# ovs-vsctl add-brvxbr

# ifconfig vxbr10.1.2.1/24

3添加vxlan类型端口,remoteiphost2ip地址

# ovs-vsctl add-portvxbr vxlan -- set interface vxlan type=vxlan options:remote_ip=10.167.226.97

# ovs-vsctl show

8671ba34-06b7-4cfe-bcf8-f84351144b5c

    Bridge vxbr

        Port vxbr

            Interface vxbr

                type: internal

        Port vxlan

            Interface vxlan

                type: vxlan

                options:{remote_ip="10.167.226.97"}

4启动没有网口的容器

#docker run --net=none --privileged=true-it 22b67c35b968 /bin/bash

给容器机指定一个eth0并绑定到宿主机的vxbr网桥

# ovs-dockeradd-port vxbr eth0 d1b7acd6da69

回到容器将eth0赋予ip地址

# ip addr add10.1.2.3/24 dev eth0

host1上可以看到vxbr有三个端口

# ovs-vsctl show

8671ba34-06b7-4cfe-bcf8-f84351144b5c

    Bridge vxbr

        Port vxbr   与自己通信

            Interface vxbr

                type: internal

        Port vxlan  vxlan端口

            Interface vxlan

                type: vxlan

                options:{remote_ip="10.167.226.97"}

        Port"9a63db7861f04_l"  docker自身通信端口

            Interface"9a63db7861f04_l"

5host2上执行以上相同的步骤,网桥ip换成10.1.2.2/24

6)关闭防火墙

#iptable -F

7通过ping测试两个容器之间的通信



0 0
原创粉丝点击