@@ -4,7 +4,7 @@ titleSuffix: Azure Load Balancer
4
4
description : This quickstart shows how to create a load balancer using Azure PowerShell.
5
5
author : mbender-ms
6
6
ms.author : mbender
7
- ms.date : 05/01/2023
7
+ ms.date : 07/23/2024
8
8
ms.topic : quickstart
9
9
ms.service : load-balancer
10
10
ms.custom : devx-track-azurepowershell, mode-api, template-quickstart, engagement-fy23
@@ -33,7 +33,7 @@ Create a resource group with [New-AzResourceGroup](/powershell/module/az.resourc
33
33
``` azurepowershell-interactive
34
34
$rg = @{
35
35
Name = 'CreatePubLBQS-rg'
36
- Location = 'eastus '
36
+ Location = 'westus2 '
37
37
}
38
38
New-AzResourceGroup @rg
39
39
```
@@ -45,8 +45,8 @@ Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress)
45
45
``` azurepowershell-interactive
46
46
$publicip = @{
47
47
Name = 'myPublicIP'
48
- ResourceGroupName = 'CreatePubLBQS-rg'
49
- Location = 'eastus '
48
+ ResourceGroupName = $rg.name
49
+ Location = 'westus2 '
50
50
Sku = 'Standard'
51
51
AllocationMethod = 'static'
52
52
Zone = 1,2,3
@@ -59,8 +59,8 @@ To create a zonal public IP address in zone 1, use the following command:
59
59
``` azurepowershell-interactive
60
60
$publicip = @{
61
61
Name = 'myPublicIP'
62
- ResourceGroupName = 'CreatePubLBQS-rg'
63
- Location = 'eastus '
62
+ ResourceGroupName = $rg.name
63
+ Location = 'westus2 '
64
64
Sku = 'Standard'
65
65
AllocationMethod = 'static'
66
66
Zone = 1
@@ -86,7 +86,7 @@ This section details how you can create and configure the following components o
86
86
## Place public IP created in previous steps into variable. ##
87
87
$pip = @{
88
88
Name = 'myPublicIP'
89
- ResourceGroupName = 'CreatePubLBQS-rg'
89
+ ResourceGroupName = $rg.name
90
90
}
91
91
$publicIp = Get-AzPublicIpAddress @pip
92
92
@@ -124,9 +124,9 @@ $rule = New-AzLoadBalancerRuleConfig @lbrule -EnableTcpReset -DisableOutboundSNA
124
124
125
125
## Create the load balancer resource. ##
126
126
$loadbalancer = @{
127
- ResourceGroupName = 'CreatePubLBQS-rg'
127
+ ResourceGroupName = $rg.name
128
128
Name = 'myLoadBalancer'
129
- Location = 'eastus '
129
+ Location = 'westus2 '
130
130
Sku = 'Standard'
131
131
FrontendIpConfiguration = $feip
132
132
BackendAddressPool = $bePool
@@ -169,20 +169,20 @@ Use a NAT gateway to provide outbound internet access to resources in the backen
169
169
## Create public IP address for NAT gateway ##
170
170
$ip = @{
171
171
Name = 'myNATgatewayIP'
172
- ResourceGroupName = 'CreatePubLBQS-rg'
173
- Location = 'eastus '
172
+ ResourceGroupName = $rg.name
173
+ Location = 'westus2 '
174
174
Sku = 'Standard'
175
175
AllocationMethod = 'Static'
176
176
}
177
177
$publicIP = New-AzPublicIpAddress @ip
178
178
179
179
## Create NAT gateway resource ##
180
180
$nat = @{
181
- ResourceGroupName = 'CreatePubLBQS-rg'
181
+ ResourceGroupName = $rg.name
182
182
Name = 'myNATgateway'
183
183
IdleTimeoutInMinutes = '10'
184
184
Sku = 'Standard'
185
- Location = 'eastus '
185
+ Location = 'westus2 '
186
186
PublicIpAddress = $publicIP
187
187
}
188
188
$natGateway = New-AzNatGateway @nat
@@ -205,8 +205,8 @@ $bastsubnetConfig = New-AzVirtualNetworkSubnetConfig @bastsubnet
205
205
## Create the virtual network ##
206
206
$net = @{
207
207
Name = 'myVNet'
208
- ResourceGroupName = 'CreatePubLBQS-rg'
209
- Location = 'eastus '
208
+ ResourceGroupName = $rg.name
209
+ Location = 'westus2 '
210
210
AddressPrefix = '10.1.0.0/16'
211
211
Subnet = $subnetConfig,$bastsubnetConfig
212
212
}
@@ -215,16 +215,16 @@ $vnet = New-AzVirtualNetwork @net
215
215
## Create public IP address for bastion host. ##
216
216
$ip = @{
217
217
Name = 'myBastionIP'
218
- ResourceGroupName = 'CreatePubLBQS-rg'
219
- Location = 'eastus '
218
+ ResourceGroupName = $rg.name
219
+ Location = 'westus2 '
220
220
Sku = 'Standard'
221
221
AllocationMethod = 'Static'
222
222
}
223
223
$publicip = New-AzPublicIpAddress @ip
224
224
225
225
## Create bastion host ##
226
226
$bastion = @{
227
- ResourceGroupName = 'CreatePubLBQS-rg'
227
+ ResourceGroupName = $rg.name
228
228
Name = 'myBastion'
229
229
PublicIpAddress = $publicip
230
230
VirtualNetwork = $vnet
@@ -249,8 +249,8 @@ $rule1 = New-AzNetworkSecurityRuleConfig @nsgrule
249
249
## Create network security group ##
250
250
$nsg = @{
251
251
Name = 'myNSG'
252
- ResourceGroupName = 'CreatePubLBQS-rg'
253
- Location = 'eastus '
252
+ ResourceGroupName = $rg.name
253
+ Location = 'westus2 '
254
254
SecurityRules = $rule1
255
255
}
256
256
New-AzNetworkSecurityGroup @nsg
@@ -283,21 +283,21 @@ $cred = Get-Credential
283
283
## Place the virtual network into a variable. ##
284
284
$net = @{
285
285
Name = 'myVNet'
286
- ResourceGroupName = 'CreatePubLBQS-rg'
286
+ ResourceGroupName = $rg.name
287
287
}
288
288
$vnet = Get-AzVirtualNetwork @net
289
289
290
290
## Place the load balancer into a variable. ##
291
291
$lb = @{
292
292
Name = 'myLoadBalancer'
293
- ResourceGroupName = 'CreatePubLBQS-rg'
293
+ ResourceGroupName = $rg.name
294
294
}
295
295
$bepool = Get-AzLoadBalancer @lb | Get-AzLoadBalancerBackendAddressPoolConfig
296
296
297
297
## Place the network security group into a variable. ##
298
298
$ns = @{
299
299
Name = 'myNSG'
300
- ResourceGroupName = 'CreatePubLBQS-rg'
300
+ ResourceGroupName = $rg.name
301
301
}
302
302
$nsg = Get-AzNetworkSecurityGroup @ns
303
303
@@ -307,8 +307,8 @@ for ($i=1; $i -le 2; $i++){
307
307
## Command to create network interface for VMs ##
308
308
$nic = @{
309
309
Name = "myNicVM$i"
310
- ResourceGroupName = 'CreatePubLBQS-rg'
311
- Location = 'eastus '
310
+ ResourceGroupName = $rg.name
311
+ Location = 'westus2 '
312
312
Subnet = $vnet.Subnets[0]
313
313
NetworkSecurityGroup = $nsg
314
314
LoadBalancerBackendAddressPool = $bepool
@@ -337,8 +337,8 @@ for ($i=1; $i -le 2; $i++){
337
337
338
338
## Create the virtual machine for VMs ##
339
339
$vm = @{
340
- ResourceGroupName = 'CreatePubLBQS-rg'
341
- Location = 'eastus '
340
+ ResourceGroupName = $rg.name
341
+ Location = 'westus2 '
342
342
VM = $vmConfig
343
343
Zone = "$i"
344
344
}
@@ -379,9 +379,9 @@ $ext = @{
379
379
Publisher = 'Microsoft.Compute'
380
380
ExtensionType = 'CustomScriptExtension'
381
381
ExtensionName = 'IIS'
382
- ResourceGroupName = 'CreatePubLBQS-rg'
382
+ ResourceGroupName = $rg.name
383
383
VMName = "myVM$i"
384
- Location = 'eastus '
384
+ Location = 'westus2 '
385
385
TypeHandlerVersion = '1.8'
386
386
SettingString = '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}'
387
387
}
@@ -408,7 +408,7 @@ Use [Get-AzPublicIpAddress](/powershell/module/az.network/get-azpublicipaddress)
408
408
409
409
``` azurepowershell-interactive
410
410
$ip = @{
411
- ResourceGroupName = 'CreatePubLBQS-rg'
411
+ ResourceGroupName = $rg.name
412
412
Name = 'myPublicIP'
413
413
}
414
414
Get-AzPublicIPAddress @ip | select IpAddress
@@ -423,7 +423,7 @@ Copy the public IP address, and then paste it into the address bar of your brows
423
423
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.
424
424
425
425
``` azurepowershell-interactive
426
- Remove-AzResourceGroup -Name 'CreatePubLBQS-rg'
426
+ Remove-AzResourceGroup -Name $rg.name
427
427
```
428
428
429
429
## Next steps
0 commit comments