@@ -5,15 +5,15 @@ description: This quickstart shows how to create an internal load balancer using
5
5
author : mbender-ms
6
6
ms.service : load-balancer
7
7
ms.topic : quickstart
8
- ms.date : 05/31/2023
8
+ ms.date : 07/23/2024
9
9
ms.author : mbender
10
10
ms.custom : devx-track-azurepowershell, mode-api, template-quickstart
11
11
# Customer intent: I want to create a load balancer so that I can load balance internal traffic to VMs.
12
12
---
13
13
14
- # Quickstart: Create an internal load balancer to load balance VMs using Azure PowerShell
14
+ # Quickstart: Create an internal load balancer to load balance virtual machines using Azure PowerShell
15
15
16
- Get started with Azure Load Balancer by using Azure PowerShell to create an internal load balancer and two virtual machines.Additional resources include Azure Bastion, NAT Gateway, a virtual network, and the required subnets.
16
+ Get started with Azure Load Balancer creating an internal load balancer and two virtual machines with Azure PowerShell. Also, you deploy other resources including Azure Bastion, NAT Gateway, a virtual network, and the required subnets.
17
17
18
18
:::image type="content" source="media/quickstart-load-balancer-standard-internal-portal/internal-load-balancer-resources.png" alt-text="Diagram of resources deployed for internal load balancer." lightbox="media/quickstart-load-balancer-standard-internal-portal/internal-load-balancer-resources.png":::
19
19
@@ -32,7 +32,11 @@ An Azure resource group is a logical container into which Azure resources are de
32
32
Create a resource group with [ New-AzResourceGroup] ( /powershell/module/az.resources/new-azresourcegroup ) .
33
33
34
34
``` azurepowershell-interactive
35
- New-AzResourceGroup -Name 'CreateIntLBQS-rg' -Location 'eastus'
35
+ $rg = @{
36
+ Name = 'CreateINTLBQS-rg'
37
+ Location = 'westus2'
38
+ }
39
+ New-AzResourceGroup @rg
36
40
```
37
41
38
42
## Configure virtual network
@@ -55,8 +59,8 @@ Use [New-AzPublicIpAddress](/powershell/module/az.network/new-azpublicipaddress)
55
59
## Create public IP address for NAT gateway and place IP in variable ##
56
60
$gwpublicip = @{
57
61
Name = 'myNATgatewayIP'
58
- ResourceGroupName = 'CreateIntLBQS-rg'
59
- Location = 'eastus '
62
+ ResourceGroupName = $rg.name
63
+ Location = 'westus2 '
60
64
Sku = 'Standard'
61
65
AllocationMethod = 'static'
62
66
Zone = 1,2,3
@@ -70,8 +74,8 @@ To create a zonal public IP address in zone 1, use the following command:
70
74
## Create a zonal public IP address for NAT gateway and place IP in variable ##
71
75
$gwpublicip = @{
72
76
Name = 'myNATgatewayIP'
73
- ResourceGroupName = 'CreateIntLBQS-rg'
74
- Location = 'eastus '
77
+ ResourceGroupName = $rg.name
78
+ Location = 'westus2 '
75
79
Sku = 'Standard'
76
80
AllocationMethod = 'static'
77
81
Zone = 1
@@ -101,11 +105,11 @@ $gwpublicip = New-AzPublicIpAddress @gwpublicip
101
105
102
106
## Create NAT gateway resource ##
103
107
$nat = @{
104
- ResourceGroupName = 'CreateIntLBQS-rg'
108
+ ResourceGroupName = $rg.name
105
109
Name = 'myNATgateway'
106
110
IdleTimeoutInMinutes = '10'
107
111
Sku = 'Standard'
108
- Location = 'eastus '
112
+ Location = 'westus2 '
109
113
PublicIpAddress = $gwpublicip
110
114
}
111
115
$natGateway = New-AzNatGateway @nat
@@ -128,8 +132,8 @@ $bastsubnetConfig = New-AzVirtualNetworkSubnetConfig @bastsubnet
128
132
## Create the virtual network ##
129
133
$net = @{
130
134
Name = 'myVNet'
131
- ResourceGroupName = 'CreateIntLBQS-rg'
132
- Location = 'eastus '
135
+ ResourceGroupName = $rg.name
136
+ Location = 'westus2 '
133
137
AddressPrefix = '10.1.0.0/16'
134
138
Subnet = $subnetConfig,$bastsubnetConfig
135
139
}
@@ -138,16 +142,16 @@ $vnet = New-AzVirtualNetwork @net
138
142
## Create public IP address for bastion host. ##
139
143
$bastionip = @{
140
144
Name = 'myBastionIP'
141
- ResourceGroupName = 'CreateIntLBQS-rg'
142
- Location = 'eastus '
145
+ ResourceGroupName = $rg.name
146
+ Location = 'westus2 '
143
147
Sku = 'Standard'
144
148
AllocationMethod = 'Static'
145
149
}
146
150
$bastionip = New-AzPublicIpAddress @bastionip
147
151
148
152
## Create bastion host ##
149
153
$bastion = @{
150
- ResourceGroupName = 'CreateIntLBQS-rg'
154
+ ResourceGroupName = $rg.name
151
155
Name = 'myBastion'
152
156
PublicIpAddress = $bastionip
153
157
VirtualNetwork = $vnet
@@ -172,8 +176,8 @@ $rule1 = New-AzNetworkSecurityRuleConfig @nsgrule
172
176
## Create network security group ##
173
177
$nsg = @{
174
178
Name = 'myNSG'
175
- ResourceGroupName = 'CreateIntLBQS-rg'
176
- Location = 'eastus '
179
+ ResourceGroupName = $rg.name
180
+ Location = 'westus2 '
177
181
SecurityRules = $rule1
178
182
}
179
183
New-AzNetworkSecurityGroup @nsg
@@ -197,7 +201,7 @@ This section details how you can create and configure the following components o
197
201
## Place virtual network created in previous step into a variable. ##
198
202
$net = @{
199
203
Name = 'myVNet'
200
- ResourceGroupName = 'CreateIntLBQS-rg'
204
+ ResourceGroupName = $rg.name
201
205
}
202
206
$vnet = Get-AzVirtualNetwork @net
203
207
@@ -236,9 +240,9 @@ $rule = New-AzLoadBalancerRuleConfig @lbrule -EnableTcpReset
236
240
237
241
## Create the load balancer resource. ##
238
242
$loadbalancer = @{
239
- ResourceGroupName = 'CreateIntLBQS-rg'
243
+ ResourceGroupName = $rg.name
240
244
Name = 'myLoadBalancer'
241
- Location = 'eastus '
245
+ Location = 'westus2 '
242
246
Sku = 'Standard'
243
247
FrontendIpConfiguration = $feip
244
248
BackendAddressPool = $bePool
@@ -276,32 +280,32 @@ $cred = Get-Credential
276
280
## Place virtual network created in previous step into a variable. ##
277
281
$net = @{
278
282
Name = 'myVNet'
279
- ResourceGroupName = 'CreateIntLBQS-rg'
283
+ ResourceGroupName = $rg.name
280
284
}
281
285
$vnet = Get-AzVirtualNetwork @net
282
286
283
287
## Place the load balancer into a variable. ##
284
288
$lb = @{
285
289
Name = 'myLoadBalancer'
286
- ResourceGroupName = 'CreateIntLBQS-rg'
290
+ ResourceGroupName = $rg.name
287
291
}
288
292
$bepool = Get-AzLoadBalancer @lb | Get-AzLoadBalancerBackendAddressPoolConfig
289
293
290
294
## Place the network security group into a variable. ##
291
- $sg = {
295
+ $sg = @ {
292
296
Name = 'myNSG'
293
- ResourceGroupName = 'CreateIntLBQS-rg' @sg
297
+ ResourceGroupName = $rg.name
294
298
}
295
- $nsg = Get-AzNetworkSecurityGroup
299
+ $nsg = Get-AzNetworkSecurityGroup @sg
296
300
297
301
## For loop with variable to create virtual machines for load balancer backend pool. ##
298
302
for ($i=1; $i -le 2; $i++)
299
303
{
300
304
## Command to create network interface for VMs ##
301
305
$nic = @{
302
306
Name = "myNicVM$i"
303
- ResourceGroupName = 'CreateIntLBQS-rg'
304
- Location = 'eastus '
307
+ ResourceGroupName = $rg.name
308
+ Location = 'westus2 '
305
309
Subnet = $vnet.Subnets[0]
306
310
NetworkSecurityGroup = $nsg
307
311
LoadBalancerBackendAddressPool = $bepool
@@ -330,8 +334,8 @@ for ($i=1; $i -le 2; $i++)
330
334
331
335
## Create the virtual machine for VMs ##
332
336
$vm = @{
333
- ResourceGroupName = 'CreateIntLBQS-rg'
334
- Location = 'eastus '
337
+ ResourceGroupName = $rg.name
338
+ Location = 'westus2 '
335
339
VM = $vmConfig
336
340
Zone = "$i"
337
341
}
@@ -370,9 +374,9 @@ for ($i=1; $i -le 2; $i++)
370
374
Publisher = 'Microsoft.Compute'
371
375
ExtensionType = 'CustomScriptExtension'
372
376
ExtensionName = 'IIS'
373
- ResourceGroupName = 'CreateIntLBQS-rg'
377
+ ResourceGroupName = $rg.name
374
378
VMName = "myVM$i"
375
- Location = 'eastus '
379
+ Location = 'westus2 '
376
380
TypeHandlerVersion = '1.8'
377
381
SettingString = '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}'
378
382
}
@@ -414,22 +418,22 @@ $cred = Get-Credential
414
418
## Place the virtual network into a variable. ##
415
419
$net = @{
416
420
Name = 'myVNet'
417
- ResourceGroupName = 'CreateIntLBQS-rg'
421
+ ResourceGroupName = $rg.name
418
422
}
419
423
$vnet = Get-AzVirtualNetwork @net
420
424
421
425
## Place the network security group into a variable. ##
422
- $sg = {
426
+ $sg = @ {
423
427
Name = 'myNSG'
424
- ResourceGroupName = 'CreateIntLBQS-rg' @sg
428
+ ResourceGroupName = $rg.name
425
429
}
426
- $nsg = Get-AzNetworkSecurityGroup
430
+ $nsg = Get-AzNetworkSecurityGroup @sg
427
431
428
432
## Command to create network interface for VM ##
429
433
$nic = @{
430
434
Name = "myNicTestVM"
431
- ResourceGroupName = 'CreateIntLBQS-rg'
432
- Location = 'eastus '
435
+ ResourceGroupName = $rg.name
436
+ Location = 'westus2 '
433
437
Subnet = $vnet.Subnets[0]
434
438
NetworkSecurityGroup = $nsg
435
439
}
@@ -457,8 +461,8 @@ $vmConfig = New-AzVMConfig @vmsz `
457
461
458
462
## Create the virtual machine for VMs ##
459
463
$vm = @{
460
- ResourceGroupName = 'CreateIntLBQS-rg'
461
- Location = 'eastus '
464
+ ResourceGroupName = $rg.name
465
+ Location = 'westus2 '
462
466
VM = $vmConfig
463
467
}
464
468
New-AzVM @vm
@@ -491,7 +495,7 @@ To see the load balancer distribute traffic across all three VMs, you can force-
491
495
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.
492
496
493
497
``` azurepowershell-interactive
494
- Remove-AzResourceGroup -Name 'CreateIntLBQS-rg'
498
+ Remove-AzResourceGroup -Name $rg.name
495
499
```
496
500
497
501
## Next steps
0 commit comments