Skip to content

Commit b6d52a5

Browse files
committed
Added PS commands
1 parent 225e5ef commit b6d52a5

File tree

1 file changed

+326
-2
lines changed

1 file changed

+326
-2
lines changed

articles/load-balancer/tutorial-create-gateway-load-balancer.md

Lines changed: 326 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,122 @@ Use [az network nsg rule create](/cli/azure/network/nsg/rule#az-network-nsg-rule
188188

189189
# [Azure PowerShell](#tab/azurepowershell/)
190190

191+
## Create a resource group
192+
193+
An Azure resource group is a logical container into which Azure resources are deployed and managed.
194+
195+
Create a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup):
196+
197+
```azurepowershell-interactive
198+
New-AzResourceGroup -Name 'TutorGwLB-rg' -Location 'eastus'
199+
200+
```
201+
202+
## Create virtual network
203+
204+
A virtual network is needed for the resources that are in the backend pool of the gateway load balancer. Use [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) to create the virtual network. Use [New-AzBastion](/powershell/module/az.network/new-azbastion) to deploy a bastion host for secure management of resources in virtual network.
205+
206+
> [!IMPORTANT]
207+
208+
> [!INCLUDE [Pricing](~/reusable-content/ce-skilling/azure/includes/bastion-pricing.md)]
209+
210+
>
211+
212+
```azurepowershell-interactive
213+
## Create backend subnet config ##
214+
$subnet = @{
215+
Name = 'myBackendSubnet'
216+
AddressPrefix = '10.1.0.0/24'
217+
}
218+
$subnetConfig = New-AzVirtualNetworkSubnetConfig @subnet
219+
220+
## Create Azure Bastion subnet. ##
221+
$bastsubnet = @{
222+
Name = 'AzureBastionSubnet'
223+
AddressPrefix = '10.1.1.0/24'
224+
}
225+
$bastsubnetConfig = New-AzVirtualNetworkSubnetConfig @bastsubnet
226+
227+
## Create the virtual network ##
228+
$net = @{
229+
Name = 'myVNet'
230+
ResourceGroupName = 'TutorGwLB-rg'
231+
Location = 'eastus'
232+
AddressPrefix = '10.1.0.0/16'
233+
Subnet = $subnetConfig,$bastsubnetConfig
234+
}
235+
$vnet = New-AzVirtualNetwork @net
236+
237+
## Create public IP address for bastion host. ##
238+
$ip = @{
239+
Name = 'myBastionIP'
240+
ResourceGroupName = 'TutorGwLB-rg'
241+
Location = 'eastus'
242+
Sku = 'Standard'
243+
AllocationMethod = 'Static'
244+
}
245+
$publicip = New-AzPublicIpAddress @ip
246+
247+
## Create bastion host ##
248+
$bastion = @{
249+
ResourceGroupName = 'TutorGwLB-rg'
250+
Name = 'myBastion'
251+
PublicIpAddress = $publicip
252+
VirtualNetwork = $vnet
253+
}
254+
New-AzBastion @bastion -AsJob
255+
256+
```
257+
258+
## Create NSG
259+
260+
Use the following example to create a network security group. You'll configure the NSG rules needed for network traffic in the virtual network created previously.
261+
262+
Use [New-AzNetworkSecurityRuleConfig](/powershell/module/az.network/new-aznetworksecurityruleconfig) to create rules for the NSG. Use [New-AzNetworkSecurityGroup](/powershell/module/az.network/new-aznetworksecuritygroup) to create the NSG.
263+
264+
```azurepowershell-interactive
265+
## Create rule for network security group and place in variable. ##
266+
$nsgrule1 = @{
267+
Name = 'myNSGRule-AllowAll'
268+
Description = 'Allow all'
269+
Protocol = '*'
270+
SourcePortRange = '*'
271+
DestinationPortRange = '*'
272+
SourceAddressPrefix = '0.0.0.0/0'
273+
DestinationAddressPrefix = '0.0.0.0/0'
274+
Access = 'Allow'
275+
Priority = '100'
276+
Direction = 'Inbound'
277+
}
278+
$rule1 = New-AzNetworkSecurityRuleConfig @nsgrule1
279+
280+
$nsgrule2 = @{
281+
Name = 'myNSGRule-AllowAll-TCP-Out'
282+
Description = 'Allow all TCP Out'
283+
Protocol = 'TCP'
284+
SourcePortRange = '*'
285+
DestinationPortRange = '*'
286+
SourceAddressPrefix = '0.0.0.0/0'
287+
DestinationAddressPrefix = '0.0.0.0/0'
288+
Access = 'Allow'
289+
Priority = '100'
290+
Direction = 'Outbound'
291+
}
292+
$rule2 = New-AzNetworkSecurityRuleConfig @nsgrule2
293+
294+
## Create network security group ##
295+
$nsg = @{
296+
Name = 'myNSG'
297+
ResourceGroupName = 'TutorGwLB-rg'
298+
Location = 'eastus'
299+
SecurityRules = $rule1,$rule2
300+
}
301+
New-AzNetworkSecurityGroup @nsg
302+
```
303+
191304
---
192305

193-
# Create and configure a gateway load balancer
306+
## Create and configure a gateway load balancer
194307
In this section, you create a gateway load balancer and configure it with a backend pool and frontend IP configuration. The backend pool is associated with the existing load balancer created in the prerequisites.
195308

196309
# [Azure portal](#tab/azureportal)
@@ -268,6 +381,96 @@ Traffic destined for the backend instances is routed with a load-balancing rule.
268381

269382
# [Azure PowerShell](#tab/azurepowershell/)
270383

384+
## Create Gateway Load Balancer
385+
386+
In this section, you'll create the configuration and deploy the gateway load balancer. Use [New-AzLoadBalancerFrontendIpConfig](/powershell/module/az.network/new-azloadbalancerfrontendipconfig) to create the frontend IP configuration of the load balancer.
387+
388+
You'll use [New-AzLoadBalancerTunnelInterface](/powershell/module/az.network/new-azloadbalancerfrontendipconfig) to create two tunnel interfaces for the load balancer.
389+
390+
Create a backend pool with [New-AzLoadBalancerBackendAddressPoolConfig](/powershell/module/az.network/new-azloadbalancerbackendaddresspoolconfig) for the NVAs.
391+
392+
A health probe is required to monitor the health of the backend instances in the load balancer. Use [New-AzLoadBalancerProbeConfig](/powershell/module/az.network/new-azloadbalancerprobeconfig) to create the health probe.
393+
394+
Traffic destined for the backend instances is routed with a load-balancing rule. Use [New-AzLoadBalancerRuleConfig](/powershell/module/az.network/new-azloadbalancerruleconfig) to create the load-balancing rule.
395+
396+
To create the deploy the load balancer, use [New-AzLoadBalancer](/powershell/module/az.network/new-azloadbalancer).
397+
398+
```azurepowershell-interactive
399+
## Place virtual network configuration in a variable for later use. ##
400+
$net = @{
401+
Name = 'myVNet'
402+
ResourceGroupName = 'TutorGwLB-rg'
403+
}
404+
$vnet = Get-AzVirtualNetwork @net
405+
406+
## Create load balancer frontend configuration and place in variable. ##
407+
$fe = @{
408+
Name = 'myFrontend'
409+
SubnetId = $vnet.subnets[0].id
410+
}
411+
$feip = New-AzLoadBalancerFrontendIpConfig @fe
412+
413+
## Create backend address pool configuration and place in variable. ##
414+
$int1 = @{
415+
Type = 'Internal'
416+
Protocol = 'Vxlan'
417+
Identifier = '800'
418+
Port = '10800'
419+
}
420+
$tunnelInterface1 = New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig @int1
421+
422+
$int2 = @{
423+
Type = 'External'
424+
Protocol = 'Vxlan'
425+
Identifier = '801'
426+
Port = '10801'
427+
}
428+
$tunnelInterface2 = New-AzLoadBalancerBackendAddressPoolTunnelInterfaceConfig @int2
429+
430+
$pool = @{
431+
Name = 'myBackendPool'
432+
TunnelInterface = $tunnelInterface1,$tunnelInterface2
433+
}
434+
$bepool = New-AzLoadBalancerBackendAddressPoolConfig @pool
435+
436+
## Create the health probe and place in variable. ##
437+
$probe = @{
438+
Name = 'myHealthProbe'
439+
Protocol = 'http'
440+
Port = '80'
441+
IntervalInSeconds = '360'
442+
ProbeCount = '5'
443+
RequestPath = '/'
444+
}
445+
$healthprobe = New-AzLoadBalancerProbeConfig @probe
446+
447+
## Create the load balancer rule and place in variable. ##
448+
$para = @{
449+
Name = 'myLBRule'
450+
Protocol = 'All'
451+
FrontendPort = '0'
452+
BackendPort = '0'
453+
FrontendIpConfiguration = $feip
454+
BackendAddressPool = $bepool
455+
Probe = $healthprobe
456+
}
457+
$rule = New-AzLoadBalancerRuleConfig @para
458+
459+
## Create the load balancer resource. ##
460+
$lb = @{
461+
ResourceGroupName = 'TutorGwLB-rg'
462+
Name = 'myLoadBalancer-gw'
463+
Location = 'eastus'
464+
Sku = 'Gateway'
465+
LoadBalancingRule = $rule
466+
FrontendIpConfiguration = $feip
467+
BackendAddressPool = $bepool
468+
Probe = $healthprobe
469+
}
470+
New-AzLoadBalancer @lb
471+
472+
```
473+
271474
---
272475

273476
## Add network virtual appliances to the Gateway Load Balancer backend pool
@@ -282,6 +485,47 @@ Deploy NVAs through the Azure Marketplace. Once deployed, add the virtual machin
282485

283486
# [Azure PowerShell](#tab/azurepowershell/)
284487

488+
In this example, you'll chain the frontend of a standard load balancer to the gateway load balancer.
489+
490+
You'll add the frontend to the frontend IP of an existing load balancer in your subscription.
491+
492+
Use [Set-AzLoadBalancerFrontendIpConfig](/powershell/module/az.network/set-azloadbalancerfrontendipconfig) to chain the gateway load balancer frontend to your existing load balancer.
493+
494+
```azurepowershell-interactive
495+
## Place the gateway load balancer configuration into a variable. ##
496+
$par1 = @{
497+
ResourceGroupName = 'TutorGwLB-rg'
498+
Name = 'myLoadBalancer-gw'
499+
}
500+
$gwlb = Get-AzLoadBalancer @par1
501+
502+
## Place the existing load balancer into a variable. ##
503+
$par2 = @{
504+
ResourceGroupName = 'CreatePubLBQS-rg'
505+
Name = 'myLoadBalancer'
506+
}
507+
$lb = Get-AzLoadBalancer @par2
508+
509+
## Place the existing public IP for the existing load balancer into a variable.
510+
$par3 = @{
511+
ResourceGroupName = 'CreatePubLBQS-rg'
512+
Name = 'myPublicIP'
513+
}
514+
$publicIP = Get-AzPublicIPAddress @par3
515+
516+
## Chain the gateway load balancer to your existing load balancer frontend. ##
517+
$par4 = @{
518+
Name = 'myFrontEndIP'
519+
PublicIPAddress = $publicIP
520+
LoadBalancer = $lb
521+
GatewayLoadBalancerId = $gwlb.FrontendIpConfigurations.Id
522+
}
523+
$config = Set-AzLoadBalancerFrontendIpConfig @par4
524+
525+
$config | Set-AzLoadBalancer
526+
527+
```
528+
285529
---
286530

287531
## Chain load balancer frontend to Gateway Load Balancer
@@ -337,6 +581,47 @@ Use [az network lb frontend-ip update](/cli/azure/network/lb/frontend-ip#az-netw
337581

338582
# [Azure PowerShell](#tab/azurepowershell/)
339583

584+
In this example, you'll chain the frontend of a standard load balancer to the gateway load balancer.
585+
586+
You'll add the frontend to the frontend IP of an existing load balancer in your subscription.
587+
588+
Use [Set-AzLoadBalancerFrontendIpConfig](/powershell/module/az.network/set-azloadbalancerfrontendipconfig) to chain the gateway load balancer frontend to your existing load balancer.
589+
590+
```azurepowershell-interactive
591+
## Place the gateway load balancer configuration into a variable. ##
592+
$par1 = @{
593+
ResourceGroupName = 'TutorGwLB-rg'
594+
Name = 'myLoadBalancer-gw'
595+
}
596+
$gwlb = Get-AzLoadBalancer @par1
597+
598+
## Place the existing load balancer into a variable. ##
599+
$par2 = @{
600+
ResourceGroupName = 'CreatePubLBQS-rg'
601+
Name = 'myLoadBalancer'
602+
}
603+
$lb = Get-AzLoadBalancer @par2
604+
605+
## Place the existing public IP for the existing load balancer into a variable.
606+
$par3 = @{
607+
ResourceGroupName = 'CreatePubLBQS-rg'
608+
Name = 'myPublicIP'
609+
}
610+
$publicIP = Get-AzPublicIPAddress @par3
611+
612+
## Chain the gateway load balancer to your existing load balancer frontend. ##
613+
$par4 = @{
614+
Name = 'myFrontEndIP'
615+
PublicIPAddress = $publicIP
616+
LoadBalancer = $lb
617+
GatewayLoadBalancerId = $gwlb.FrontendIpConfigurations.Id
618+
}
619+
$config = Set-AzLoadBalancerFrontendIpConfig @par4
620+
621+
$config | Set-AzLoadBalancer
622+
623+
```
624+
340625
---
341626

342627
## Chain virtual machine to Gateway Load Balancer
@@ -396,6 +681,39 @@ Use [az network lb frontend-ip update](/cli/azure/network/nic/ip-config#az-netwo
396681

397682
# [Azure PowerShell](#tab/azurepowershell/)
398683

684+
Alternatively, you can chain a VM's NIC IP configuration to the gateway load balancer.
685+
686+
You'll add the gateway load balancer's frontend to an existing VM's NIC IP configuration.
687+
688+
Use [Set-AzNetworkInterfaceIpConfig](/powershell/module/az.network/set-aznetworkinterfaceipconfig) to chain the gateway load balancer frontend to your existing VM's NIC IP configuration.
689+
690+
```azurepowershell-interactive
691+
## Place the gateway load balancer configuration into a variable. ##
692+
$par1 = @{
693+
ResourceGroupName = 'TutorGwLB-rg'
694+
Name = 'myLoadBalancer-gw'
695+
}
696+
$gwlb = Get-AzLoadBalancer @par1
697+
698+
## Place the existing NIC into a variable. ##
699+
$par2 = @{
700+
ResourceGroupName = 'MyResourceGroup'
701+
Name = 'myNic'
702+
}
703+
$nic = Get-AzNetworkInterface @par2
704+
705+
## Chain the gateway load balancer to your existing VM NIC. ##
706+
$par3 = @{
707+
Name = 'myIPconfig'
708+
NetworkInterface = $nic
709+
GatewayLoadBalancerId = $gwlb.FrontendIpConfigurations.Id
710+
}
711+
$config = Set-AzNetworkInterfaceIpConfig @par3
712+
713+
$config | Set-AzNetworkInterface
714+
715+
```
716+
399717
---
400718

401719
## Clean up resources
@@ -417,6 +735,12 @@ When no longer needed, you can use the [az group delete](/cli/azure/group#az-gro
417735

418736
# [Azure PowerShell](#tab/azurepowershell/)
419737

738+
When no longer needed, you can use the [Remove-AzResourceGroup](/powershell/module/az.resources/remove-azresourcegroup) command to remove the resource group, load balancer, and the remaining resources.
739+
740+
```azurepowershell-interactive
741+
Remove-AzResourceGroup -Name 'TutorGwLB-rg'
742+
```
743+
420744
---
421745

422746
## Next steps
@@ -435,4 +759,4 @@ When creating the NVAs, choose the resources created in this tutorial:
435759

436760
Advance to the next article to learn how to create a cross-region Azure Load Balancer.
437761
> [!div class="nextstepaction"]
438-
> [Cross-region load balancer](tutorial-cross-region-portal.md)
762+
> [Global load balancer](tutorial-cross-region-portal.md)

0 commit comments

Comments
 (0)