Hype Beats Truth: Why You Should Care About VMware NSXT
作者:禅与计算机程序设计艺术
1.简介
2020年份期间,在云计算快速发展的背景下
在文章开篇部分
随着数据中心规模不断扩大以及应用场景日益复杂化
当前技术革新速度之快令人瞩目
当谈到NSX-T时
总体而言
所以,如果你是一位技术专家,并且具备高度的责任心,则期待有一篇专业的技术博客文章来系统阐述NSX-T的基本知识、核心特性及其实际应用方法。这样的专业分享非常适合你阅读。
2.基本概念术语说明
2.1.网络结构
网络结构定义了当前网络中各节点之间的连接关系,并指出了信息传递的具体路径。例如常见的设备如物理交换机和路由器,并指出了网络中各节点间的信息传递路径。
通常情况下,一个网络系统会被划分为三个层级的架构。
具体包括物理层、数据链路层以及网络传输层。
物理层:物理层是直接与网络连接的媒介,包括电缆、光纤等。
数据链路层:该层负责将数据从源端发送至目的端,在物理介质的基础上构建相应的逻辑通信通道。其主要实现方式包括:采用点对点连接(PPP)实现本地直连;基于广播机制实现多设备共享通信(Bridging);以及通过独立通道实现特定两台设备间的专用通信(Point to Point)。
在网络层面:该层负责为数据选择路由路径并确定其前往的目标节点路由器。该层级包含多个核心协议系统:其中主要包括IP(Internet Protocol)用于数据分组标识与传输;ICMP(Internet Control Message Protocol)处理网络控制与错误报告功能;以及ARP(Address Resolution Protocol)实现主机间地址解析与通信连接建立等功能。
以上三层的网络结构如下图所示:
2.2.SDN(Software Defined Networking)
软件定义网络(SDN)是将网络功能通过软件实现的一种技术体系。它不仅能够实现网络虚拟化,并且能够使网络设备的控制平面、计算平面和存储平面功能分别通过硬件向软件迁移。
2.3.Network Virtualization Platform
NVP(Network Virtualization Platform)是一组用于构建、维护以及配置虚拟网络环境的集成工具体系。该平台由控制器、编排引擎以及配置语言三部分构成,并通过这些组件协同工作以实现虚拟网络的管理与调度功能。
NVP控制器部署于网络边界的边缘区域,并负责对各类网络资源进行动态分配与优化配置。该控制器的主要职责包括对交换机、路由器以及防火墙等关键设备进行全生命周期管理,并提供实时监控和故障排查服务。
编排引擎负责管理网络虚拟环境中的底层资源模型,并阐述其应用需求和服务质量保障的同时,在服务质量保证方面也具备较强的稳定性与可靠性。编排引擎将网络虚拟化平台的所有核心资源按照用户指定的网络拓扑进行动态抽象,并由控制器对这些抽象出的资源进行动态分配与优化配置以确保系统的高效运行。
编排语言是一种基于符号的描述方式,在网络资源的配置与部署方面发挥重要作用。它采用声明式模板语法结构,在确定了所需配置需求后,用户需要先进行编译操作。随后完成脚本部署后,在系统运行状态下NVP将根据预先编写好的规则自动执行相应的任务序列。
3.核心算法原理和具体操作步骤以及数学公式讲解
VMware NSX-T是 VMware 在 VMware Cloud on AWS (VMC on AWS) 上推出的第二代分布式虚拟网络解决方案。该方案基于 VMware NSXv 和 VSP 技术,在同一台 vCenter 服务器上实现统一部署与管理功能。NSX-T 包含两种核心架构模式:
采用封装策略:NSX-T支持通过该策略将外部网络打包成NSX网关上的VLAN。这使得无需改动现有的物理网络架构即可实现更大规模的承载能力和更高的可靠性。此外,在不增加额外资源的情况下实现与传统型网络的有效结合。
2、隧道模式:隧道模式能够兼容现有的基于BGP的VPN架构或第三方应用集成,并且能够高效地实现外部网络资源的接入到NSX-T中的虚拟机。
3.1.封装模式
该方案采用VMware NSX-T作为封装框架,在软件定义的网络架构基础上实现了对外部网络资源的有效整合与管理策略设计。通过将外部网络设备资源集中配置到NSX网关上的VLAN端口上,在确保原有物理架构稳定运行的同时显著提升了整体承载能力和可靠性
创建封装策略
用户可以通过NSX-T Manager管理界面以及CLI来配置封装策略。若要创建一个新的封装策略,请必须配置相应的参数设置。
1、Name:命名封装策略
2、Source Gateway:选择要打包的外部网络的NSX网关
3、VLAN ID:选择要使用的VLAN ID
4、Subnet:指定VLAN的子网掩码
5、Services:决定开放供用户使用的各项服务。可选配置包括支持的协议(如TCP、UDP、ICMP),同时支持跳转至其他区域网络的协议。
6、高级配置选项:在本高级配置选项中提供封装类型和网络扩展功能的选择项,在此高级设置下可启用或配置相关参数以实现所需的功能需求。
Associated Logical Switch:可选项设置中的一项,在配置相关联的逻辑交换机时需进行设置。仅在VM访问外部网络时才涉及此设置。
{
"name": "Packing External Network",
"source_gateway_id": "e71f7d5b-ffba-47ed-bcfa-b1d37a0fb4ef",
"vlan_id": 100,
"subnet": "192.168.1.0/24",
"services": [
{"protocol": "tcp"},
{"protocol": "udp"}
],
"advanced_config": {},
"associated_logical_switch_port_id": null,
"resource_type": "Segment"
}
代码解读
配置防火墙规则
为了使用户能够在VLAN上暴露特定服务,请配置相应的防火墙规则。防火墙规则用于管理来自外部网络的访问权限。在VLAN的上下文菜单中可以添加防火墙规则。单击‘VLAN’选项,在其操作菜单中找到并选择‘Add Firewall Rule’选项进行配置设置。
1、Name:命名规则
2、Direction:方向,可选值:Ingress、Egress
3、Action:动作,可选值:Allow、Deny
4、Protocol:协议,可选值:IPv4/IPv6、TCP、UDP、ICMP
5、Scope:作用域,可选值:Global、Local
6、Destination IP Address:目的IP地址
7、Destination Port:目的端口范围
8、Description:描述信息,可以选择性填充
{
"action": "allow",
"description": "",
"destination_ip_addresses": ["*"],
"destination_ports": [],
"direction": "ingress",
"logging": false,
"name": "HTTP Traffic from Internet",
"notes": "",
"profiles": [],
"scope": "global",
"sequence_number": 10,
"service": [{"tags": []}],
"source_groups": [],
"sources": [{"origin_type": "ANY"}],
"tag_expression": ""
}
代码解读
添加Logical Router Route
该步骤为可选选项。当虚拟机(VM)需接入外部网络时,则需配置Logical Router Route。该参数明确了该VM的出口路径,并指向对应所属的VLAN ID及其相关路由器设置。
单击 Logical Router 导航至 编辑页面,在此界面中,请选择 Routes 标签,并单击 'Add Route' 按钮以创建新的路由
1、Name:命名路由
2、Type:选择静态路由类型
3、Network:选择VLAN的CIDR块
4、Next Hop:选择VLAN所在的路由器
{
"name": "DefaultRoute",
"network": "0.0.0.0/0",
"next_hop": {
"target_type": "Router",
"target_id": "12eb1f2c-80da-4f4f-be93-cf977fd947cd"
},
"admin_state": true,
"operational_state": "UP",
"resource_type": "StaticRoutingConfig"
}
代码解读
测试封装
创建完成后即可进行打包效果测试。
完成封装策略后即可进行打包效果测试。
通过ping或Traceroute命令可检测封装后的网络连通性状态。
此外,在确认VLAN已正确打包时,请确保VLAN相关参数已设置正确。
更新封装策略
用户无需特定时间即可更新封装策略。通过删除封装策略中的对应条目可成功禁用该VLAN上的服务。无需编辑封装策略即可完成VLAN服务或子网大小的更新。
删除封装策略
封装策略可通过NSX-T Manager界面或CLI进行删除。对于单个封装策略的删除操作,请在封装策略列表中右键选择"删除"选项完成操作。需要注意的是,在该VLAN上若还有运行中的VM设备,则可能引发冲突;因此必须确保在尝试从该VLAN中移除封装策略前,请将所有相关VM关闭。
3.2.隧道模式
作为VMware NSX-T中的另一种部署方案,“隧道”模式允许用户整合现有的基于BGP的VPN解决方案或第三方应用。“隧道”模式为用户提供了一种便捷的方式,并使他们能够轻松地将外部网络扩展至NSX-T中;同时无需面对复杂的网络架构变更挑战。
配置VPN
用户应先安装VPN设备并设置好相关路由参数。通常情况下,该设备会自动生成对应的BGP邻居配置信息,并为NSX-T网络虚拟化平台提供必要的连接依据。
配置Logical Tunnel Endpoint
用户可利用NSX-T Manager或CLI创建Logical Tunnel Endpoint。请参考以下步骤设置Logical Tunnel Endpoint的各项参数。
1、Name:命名Logical Tunnel Endpoint
2、Description:描述信息
3、Logical Switch:选择要绑定的逻辑交换机
4、Address:指定隧道的本地地址
5、BGP Neighbors:指定隧道的BGP邻居
6、Logical Router:选择要绑定的逻辑路由器
7、DSCP Priority:选择DSCP标记
{
"display_name": "TunnelEndpoint",
"description": "",
"transport_zone_endpoints": [
{
"transport_zone_id": "9bcfc5ce-cb5a-4a1f-a1dc-a3b8faaa1a40"
}
],
"logical_switch_id": "70fe0086-d90f-497b-9fa2-a8c84a28d101",
"address_bindings": [
{
"ip_address": "172.16.1.2/30"
}
],
"bgp_neighbor_paths": [
{
"bgp_neighbor": {
"ip_or_hostname": "172.16.1.1"
}
}
],
"routing_instance_ids": [
"/infra/tier-1s/vmc/segments/ServiceSegment/routing-instances/default-routing-instance"
],
"overlay_encap": "vxlan",
"resource_type": "LogicalTunnelEndpoint",
"enable_standby_relocation": false,
"ha_mode": "ACTIVE_STANDBY",
"active_active": false,
"preferred_path": "TIER1"
}
代码解读
配置隧道策略
设置隧道策略时可定义传输介质类型的隧道参数,并指定了对应的传输通道类型、优先等级以及默认启动端口等细节。这些设置可通过以下参数项完成:
1、Name:命名隧道策略
2、Description:描述信息
3、Rules:配置隧道策略的具体规则
4、Advertise:开启或关闭策略的advertise属性
5、Peer Address:指定VPN设备的IP地址
6、Local Address:指定隧道的本地IP地址
7、Secure Bindings:启用或关闭Secure Bindings属性
8、Preshared Key:输入预共享秘钥
9、DPD Probes:配置和管理DPD探针
10、Monitoring:启用或关闭监控功能
{
"display_name": "TunnelPolicy",
"description": "",
"rules": [
{
"resource_type": "L2VpnRule",
"l2vpn_endpoint": "A0E8BFBE-E0FF-4D3F-B399-B8ABF3BCB7F1",
"enabled": true,
"order": 0,
"destinations": [
{
"subnets": [{
"ip_addresses": ["10.155.0.0/16"]
}],
"l2vpn_service": "Any"
}
]
}
],
"tunnel_migration_enabled": false,
"tunnel_port_capacity": 10,
"dpd_probe": null,
"peer_ip": "172.16.1.1",
"local_ip": "172.16.1.2",
"secured_bindings_enabled": false,
"preshared_key": null,
"enable_monitor": false,
"resource_type": "IpSecVpnTunnelProfile",
"default_rule_logging": false,
"dns_firewall_profile_id": null,
"metadata": {}
}
代码解读
测试隧道
在完成隧道模式配置后即可开展下一步工作。通过使用ping命令或tracert命令能够验证该通道是否可达。网络管理员可进入指定端口以获取流量统计信息、校验IPSec通道状态以及系统日志信息等详细数据。
更新隧道策略
用户可随时更新隧道策略;对于更换VPN设备或重新配置逻辑交换机的情况,则可移除该对应规则。
删除隧道
用户可以通过NSX-T Manager或CLI工具进行隧道删除操作。若需移除 Logical Tunnel Endpoint,请访问编辑器界面,在左侧导航栏中找到Logical Tunnel Endpoints列表项后进行选择并执行相应的删除操作;若需清除 IPSEC VPN Tunnel Profile,请进入编辑器并定位至IPSEC VPN Tunnel Profile设置项完成删除流程。需要注意的是,在移除所有当前存在的隧道配置后方能进行逻辑交换机节点的删除操作以避免冲突风险。
4.具体代码实例和解释说明
本节介绍如何使用VMware NSX-T实现封装和隧道模式。
4.1.封装模式
使用Python客户端创建封装策略
以下代码示例展示了如何通过Python客户端实现封装策略的创建。为了执行此操作,请确保已安装vmware-nsx-client库。
Step 1: 安装vmware-nsx-client库
pip install --upgrade vmware-nsx-client
代码解读
Step 2: 创建NSX API客户端实例
from com.vmware.nsx_policy.model_client import Segment, ApiError
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
from com.vmware.nsx_policy.infra_client import TransportZones
client_config = StubConfigurationFactory.new_std_configuration('https://nsxmanager.example.com', 'username', 'password')
nsx_client = PolicyApi(client_config)
代码解读
Step 3: 获取VLAN段
vlan_segment = None
try:
for segment in nsx_client.infra.Segments.list():
if isinstance(segment, Segment) and segment.display_name == 'External VLAN':
vlan_segment = segment
break
except ApiException as e:
print("Exception when calling Segments->list: %s
" % e)
if not vlan_segment:
raise Exception('Cannot find External VLAN segment.')
代码解读
Step 4: 创建封装策略
packing_spec = create_packing_spec() # 创建封装策略参数对象
packing_params = {"name": "Packing External Network",
"source_gateway_id": "a635fc62-99b8-4ea6-afcc-026bf191704e", # 指定外部网络的NSX网关ID
"vlan_id": 100, # 指定VLAN ID
"subnet": "192.168.1.0/24", # 指定VLAN子网
"services": [{'protocol': 'tcp'}, {'protocol': 'udp'}], # 指定要暴露的服务
"advanced_config": {}} # 设置高级选项
try:
response = nsx_client.infra.SegmentDiscoveryProfiles.create_or_update(vlan_segment.id,
packing_params,
True,
60) # 执行封装策略
except (ApiException, IOError) as e:
print("Exception when calling SegmentDiscoveryProfiles->create_or_update: %s
" % e)
代码解读
Step 5: 检查封装策略创建结果
segment_discovery_profile = get_pack_profile() # 获取封装策略对象
while segment_discovery_profile.status!= "success": # 判断封装策略执行状态
time.sleep(5) # 每隔5秒获取一次状态
try:
segment_discovery_profile = nsx_client.infra.SegmentDiscoveryProfiles.get(vlan_segment.id,
packing_params['name'])
except (ApiException, IOError) as e:
print("Exception when calling SegmentDiscoveryProfiles->get: %s
" % e)
if segment_discovery_profile is None or \
len(segment_discovery_profile.errors) > 0 or \
len(segment_discovery_profile.warnings) > 0:
print("Packing policy failed.
")
break
else:
print("%s status: %s." % (segment_discovery_profile.profile_id,
segment_discovery_profile.status))
if segment_discovery_profile.status == "success":
print("Packing policy successful.")
代码解读
Step 6: 配置防火墙规则
firewall_rule_params = {"name": "HTTP Traffic from Internet",
"direction": "IN_OUT", # 方向
"action": "ALLOW", # 操作
"ip_version": "IPV4_IPV6", # IP版本
"scope": "GLOBAL", # 作用域
"enabled": True} # 是否启用
rules_client = nsx_client.infra.FirewallRules
rule = None
try:
for r in rules_client.list(vlan_segment.id):
if r.display_name == 'HTTP Traffic from Internet':
rule = r
break
if rule:
update_response = rules_client.update(vlan_segment.id,
rule.id,
firewall_rule_params)
else:
add_response = rules_client.add(vlan_segment.id,
firewall_rule_params)
except (ApiException, IOError) as e:
print("Exception when calling FirewallRules->list: %s
" % e)
代码解读
Step 7: 创建Logical Router Route
lr_route_params = {"name": "DefaultRoute",
"description": "",
"network": "0.0.0.0/0",
"next_hop": {"target_type": "Router",
"target_id": router_id}}
routes_client = nsx_client.infra.LogicalRouterPorts
route = None
try:
for r in routes_client.list(lr_id=router_id, attachment_type='ROUTER_LINK'):
if r.display_name == 'DefaultRoute':
route = r
break
if route:
routes_client.update(lr_id=router_id,
port_id=route.id,
logical_router_link_port_params=lr_route_params)
else:
routes_client.create(lr_id=router_id,
logical_router_link_port_params=lr_route_params)
except (ApiException, IOError) as e:
print("Exception when calling LogicalRouterPorts->list: %s
" % e)
代码解读
Step 8: 测试封装策略
test_packed_network() # 测试封装后的网络连通性
代码解读
上述流程包含了创建封装策略、配置防火墙规则以及构建了逻辑路由器路由,并进行了封装策略测试的完整过程。
4.2.隧道模式
使用Python客户端创建隧道策略
在此处展示如何操作Python客户端以创建隧道策略。该库被安装。
Step 1: 安装vmware-nsx-client库
pip install --upgrade vmware-nsx-client
代码解读
Step 2: 创建NSX API客户端实例
from com.vmware.nsx_policy.model_client import ApiError, IpSecVpnTunnelProfile, EdgeCluster
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
from com.vmware.nsx_policy.infra_client import TransportZones, LogicalSwitches
client_config = StubConfigurationFactory.new_std_configuration('https://nsxmanager.example.com', 'username', 'password')
nsx_client = PolicyApi(client_config)
代码解读
Step 3: 获取Edge Cluster
edge_cluster = get_edge_cluster() # 根据集群名称获取集群对象
代码解读
Step 4: 创建Transport Zone
transport_zone_params = {"display_name": "TunnelTZ",
"description": "",
"host_switch_name": "nvds1",
"host_switch_type": "NVDS",
"tags": []}
tz_client = nsx_client.infra.Zones
zone = None
try:
for z in tz_client.list():
if z.display_name == 'TunnelTZ':
zone = z
break
if zone:
updated_tz = tz_client.update(zone.id, transport_zone_params)
else:
created_tz = tz_client.create(transport_zone_params)
except (ApiException, IOError) as e:
print("Exception when calling Zones->list: %s
" % e)
代码解读
Step 5: 创建逻辑交换机
ls_params = {"transport_zone_endpoints": [
{"transport_zone_id": zone.id}
]}
switch_client = nsx_client.infra.LogicalSwitches
sw_created = False
attempts = 0
while not sw_created and attempts < MAX_RETRIES:
attempts += 1
display_name = f'tunnel-{attempts}'
ls_params["display_name"] = display_name
try:
ls_created = switch_client.create(ls_params)
sw_created = True
except ApiException as ae:
error_body = json.loads(ae.body)["error_list"][0]["detail"]
if error_body.startswith('LogicalSwitch with this name already exists'):
continue
else:
raise ae
代码解读
Step 6: 创建IPSec VPN Tunnel Profile
ipsec_params = {"display_name": "TunnelPolicy",
"description": "",
"tunnel_migration_enabled": False,
"tunnel_port_capacity": 10,
"dpd_probe": None,
"peer_ip": "172.16.1.1",
"local_ip": "172.16.1.2",
"secured_bindings_enabled": False,
"preshared_key": None,
"enable_monitor": False,
"rules": [{"resource_type": "L2VpnRule",
"l2vpn_endpoint": "A0E8BFBE-E0FF-4D3F-B399-B8ABF3BCB7F1",
"enabled": True,
"order": 0,
"destinations": [{"subnets": [
{"ip_addresses": ["10.155.0.0/16"]}]}]}],
"default_rule_logging": False,
"dns_firewall_profile_id": None,
"metadata": {}}
profile_client = nsx_client.infra.IpsecVpnTunnelProfiles
profile_created = False
attempts = 0
while not profile_created and attempts < MAX_RETRIES:
attempts += 1
profile_params = copy.deepcopy(ipsec_params)
profile_params["display_name"] = f"{profile_params['display_name']}-{attempts}"
try:
profile = profile_client.create(profile_params)
profile_created = True
except ApiException as ae:
error_body = json.loads(ae.body)["error_list"][0]["detail"]
if error_body.startswith('Object with the same identifier already exists'):
continue
else:
raise ae
profile_id = profile.id
代码解读
Step 7: 创建Logical Tunnel Endpoint
ltep_params = {"display_name": "TunnelEndpoint",
"description": "",
"transport_zone_endpoints": [{"transport_zone_id": zone.id}],
"logical_switch_id": ls_created.id,
"address_bindings": [{"ip_address": "172.16.1.2/30"}],
"bgp_neighbor_paths": [{"bgp_neighbor": {"ip_or_hostname": "172.16.1.1"}}],
"routing_instance_ids": ["/infra/tier-1s/vmc/segments/ServiceSegment/routing-instances/default-routing-instance"],
"overlay_encap": "vxlan",
"resource_type": "LogicalTunnelEndpoint",
"enable_standby_relocation": False,
"ha_mode": "ACTIVE_STANDBY",
"active_active": False,
"preferred_path": "TIER1"}
endpoint_client = nsx_client.infra.LogicalTunnelEndpoints
ep_created = False
attempts = 0
while not ep_created and attempts < MAX_RETRIES:
attempts += 1
ltep_params["display_name"] = f"{ltep_params['display_name']}-{attempts}"
try:
endpoint = endpoint_client.create(ltep_params)
ep_created = True
except ApiException as ae:
error_body = json.loads(ae.body)["error_list"][0]["detail"]
if error_body.startswith('Object with the same identifier already exists'):
continue
else:
raise ae
endpoint_id = endpoint.id
代码解读
Step 8: 测试隧道策略
check_tunneled_traffic() # 测试隧道后端网络连通性
代码解读
上述流程涵盖了从创建隧道策略到测试隧道策略的全部环节,并具体包括了建立Transport Zone、构建逻辑交换机以及配置Logical Tunnel Endpoint
5.未来发展趋势与挑战
VMware NSX-T持续进行性能优化与功能提升,在网络功能虚拟化方案中现支持网络功能虚拟化方案中的封装与传输技术,并计划在软件定义网络(SDN)以及网络功能虚拟化(NFV)等新兴技术领域推进创新。未来的发展方向包括:
混合云:现有的NSX-T架构仅限于私有云环境的支持,在实际应用中推广至混合云环境将面临诸多技术挑战与资源分配问题。随着云计算技术的发展趋向成熟化与商业化方向,在这一进程中VMware NSX-T所采用的独特封装模式将成为推动混合云计算进程的重要技术支撑。
2、SDN:基于VMware NSX-T的软件定义网络架构设计通过其模块化架构实现快速部署和运维能力,在技术上实现了网络功能与应用系统的分离,并在市场推广方面取得了显著成效,缩短至进入商用市场的交付周期。
容器编排:随着容器编排的发展,在VMware NSX-T中相关的封装机制将会被进一步完善以促进容器应用在跨主机环境下的迁移及复制过程。
4、NFV:NFV(Network Function Virtualization)主要体现在网络功能的虚拟化方面。在5G、软件定义网络(SDN)以及网络功能虚拟化(NFV)等新兴技术推动下,VMware NSX-T将成为实现网络功能虚拟化部署的综合解决方案。
