Kolla中配置OpenStack虚机网络vxlan和vlan共存

OpenStack Neutron网络服务定义了四种网络模式:

1
2
3
4
# tenant_network_type = local
# tenant_network_type = vlan
# tenant_network_type = gre
# tenant_network_type = vxlan

这里,本文以vlan、vxlan为例,阐述如何实现OpenStack虚机网络(亦称租户网络、业务网络)同时支持vxlan和vlan两种网络。

说明

  • 环境:Openstack queens版本
  • 部署工具:kolla-ansible

在kolla-ansible部署节点的/etc/kolla/globals.yml文件中,配置网卡。如下所示。

image

  • eth0:openstack管理网络;vlan 51,交换机端口设置为Access模式
  • eth1:虚机网络(vxlan);vlan 52,交换机端口设置为Access模式
  • eth2:外部网络兼虚机网络(vlan);vlan网段53-54,交换机端口设置为trunk模式,主机不配置IP地址

在所有网络节点上,操作如下

修改文件/etc/kolla/neutron-server/ml2_conf.ini

image

修改文件/etc/kolla/neutron-openvswitch-agent/ml2_conf.ini

image

重启neutron容器

1
# docker restart neutron_server neutron_openvswitch_agent

在网络节点上,查看br-ex网桥设置情况,如下。

image

在所有计算节点上,操作如下

修改文件/etc/kolla/neutron-openvswitch-agent/ml2_conf.ini

image

创建一个br-ex外部网桥,并关联到主机的eth2物理网卡上。这样,当计算节点上的虚拟机使用vlan网络时,便可以直接通过qbr->br-int->br-ex->eth2连接到外网。(vlan网络的三层路由,建议使用物理路由器,这样性能和稳定性更好,而不需要通过网络节点上的L3 vRouter虚拟路由)。

1
2
# docker exec -u root -it neutron_openvswitch_agent ovs-vsctl add-br br-ex
# docker exec -u root -it neutron_openvswitch_agent ovs-vsctl add-port br-ex eth2

最后,重启相关容器

1
# docker restart neutron_openvswitch_agent

在计算节点上,查看br-ex网桥设置情况,如下。

image

创建一个vlan id为53的网段

1
2
3
# neutron net-create vlan-53 --shared --provider:physical_network physnet1 --provider:network_type vlan --provider:segmentation_id 53

# neutron subnet-create vlan-53 172.17.53.0/24 --name provider-53-subnet --gateway 172.17.53.1

查看创建的网络,如下。

1
2
3
4
5
6
7
8
# neutron net-list
+--------------------------------------+----------------+----------------------------------+-----------------------------------------------------+
| id | name | tenant_id | subnets |
+--------------------------------------+----------------+----------------------------------+-----------------------------------------------------+
| 5d9c4874-e03b-4bde-aee0-947d7dde4860 | vlan-53 | 48fbadff0ab84229b429166babbe488f | 9bade37c-ff44-4004-8e82-20d61348fdc0 172.17.53.0/24 |
| 7b0152da-a975-4dbf-b35b-437951c66efa | tenant_network | 48fbadff0ab84229b429166babbe488f | a45516a4-4ce9-4c2e-8052-8c71eae0e219 10.0.0.0/24 |
| 9630cf8b-4072-415b-a9a9-99ff815748f8 | public_network | 48fbadff0ab84229b429166babbe488f | a98f8c80-78de-43ba-af52-d86c19fc59ef 172.17.54.0/24 |
+--------------------------------------+----------------+----------------------------------+-----------------------------------------------------+

最后,创建一个虚拟机并使用该vlan网络。

1
2
3
4
# nova boot --flavor 1Gmem_1cpu --image centos7 --nic net-id=5d9c4874-e03b-4bde-aee0-947d7dde4860 test_vm

# nova list | grep test_vm
| f506129b-610f-4e2d-886b-5d791cdcb282 | test_vm | ACTIVE | - | Running | vlan-53=172.17.53.7

测试虚拟机网络通信

1
2
3
4
5
6
# ping -c 4 172.17.53.7
PING 172.17.53.7 (172.17.53.7) 56(84) bytes of data.
64 bytes from 172.17.53.7: icmp_seq=1 ttl=63 time=0.421 ms
64 bytes from 172.17.53.7: icmp_seq=2 ttl=63 time=0.503 ms
64 bytes from 172.17.53.7: icmp_seq=3 ttl=63 time=0.543 ms
64 bytes from 172.17.53.7: icmp_seq=4 ttl=63 time=0.469 ms

br-int和br-ex说明

  • br-int

br-int是OpenVswitch中的集成网桥,类似于一个二层的交换机。上面挂载了大量的agent来提供各种网络服务,另外负责对发往br-ex的流量,实现local vlan转化为外部vlan。

1
2
3
4
5
# ovs-ofctl dump-flows br-int  
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=147294.121s, table=0, n_packets=224, n_bytes=33961, idle_age=13, hard_age=65534, priority=3,in_port=4,dl_vlan=1 actions=mod_vlan_vid:101,NORMAL
cookie=0x0, duration=603538.84s, table=0, n_packets=19, n_bytes=2234, idle_age=18963, hard_age=65534, priority=2,in_port=4 actions=drop
cookie=0x0, duration=603547.134s, table=0, n_packets=31901, n_bytes=6419756, idle_age=13, hard_age=65534, priority=1 actions=NORMAL

  • br-ex

br-ex是OpenVswitch中的一个外部网桥,要做的事情很简单,只需要正常转发数据流量即可。

1
2
3
# ovs-ofctl dump-flows br-ex  
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=6770.969s, table=0, n_packets=5411, n_bytes=306944, idle_age=0, hard_age=65534, priority=0 actions=NORMAL

0%