Skip to content

Commit 20c253d

Browse files
authored
Merge pull request #192788 from asudbring/lbbasic-1
Added internal basic load balancer CLI article for basic sku rework
2 parents a808b62 + d528a79 commit 20c253d

File tree

3 files changed

+363
-1
lines changed

3 files changed

+363
-1
lines changed
Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
---
2+
title: 'Quickstart: Create an internal basic load balancer - Azure CLI'
3+
titleSuffix: Azure Load Balancer
4+
description: This quickstart shows how to create an internal basic load balancer by using the Azure CLI.
5+
author: asudbring
6+
ms.service: load-balancer
7+
ms.topic: quickstart
8+
ms.date: 03/24/2022
9+
ms.author: allensu
10+
ms.custom: mvc, devx-track-js, devx-track-azurecli, mode-api
11+
#Customer intent: I want to create a load balancer so that I can load balance internal traffic to VMs.
12+
---
13+
# Quickstart: Create an internal basic load balancer to load balance VMs by using the Azure CLI
14+
15+
Get started with Azure Load Balancer by using the Azure CLI to create an internal load balancer and two virtual machines.
16+
17+
[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)]
18+
19+
[!INCLUDE [azure-cli-prepare-your-environment.md](../../../includes/azure-cli-prepare-your-environment.md)]
20+
21+
This quickstart requires version 2.0.28 or later of the Azure CLI. If you're using Azure Cloud Shell, the latest version is already installed.
22+
23+
## Create a resource group
24+
25+
An Azure resource group is a logical container into which you deploy and manage your Azure resources.
26+
27+
Create a resource group with [az group create](/cli/azure/group#az_group_create).
28+
29+
```azurecli
30+
az group create \
31+
--name CreateIntLBQS-rg \
32+
--location westus3
33+
34+
```
35+
36+
When you create an internal load balancer, a virtual network is configured as the network for the load balancer.
37+
38+
## Create the virtual network
39+
40+
Before you deploy VMs and test your load balancer, create the supporting virtual network and subnet. The virtual network and subnet will contain the resources deployed later in this article.
41+
42+
Create a virtual network by using [az network vnet create](/cli/azure/network/vnet#az_network_vnet_create).
43+
44+
```azurecli
45+
az network vnet create \
46+
--resource-group CreateIntLBQS-rg \
47+
--location westus3 \
48+
--name myVNet \
49+
--address-prefixes 10.1.0.0/16 \
50+
--subnet-name myBackendSubnet \
51+
--subnet-prefixes 10.1.0.0/24
52+
```
53+
54+
## Create an Azure Bastion host
55+
56+
In this example, you'll create an Azure Bastion host. The Azure Bastion host is used later in this article to securely manage the virtual machines and test the load balancer deployment.
57+
58+
59+
### Create a bastion public IP address
60+
61+
Use [az network public-ip create](/cli/azure/network/public-ip#az_network_public_ip_create) to create a public IP address for the Azure Bastion host.
62+
63+
```azurecli
64+
az network public-ip create \
65+
--resource-group CreateIntLBQS-rg \
66+
--name myBastionIP \
67+
--sku Standard \
68+
--zone 1 2 3
69+
```
70+
### Create a bastion subnet
71+
72+
Use [az network vnet subnet create](/cli/azure/network/vnet/subnet#az_network_vnet_subnet_create) to create a subnet.
73+
74+
```azurecli
75+
az network vnet subnet create \
76+
--resource-group CreateIntLBQS-rg \
77+
--name AzureBastionSubnet \
78+
--vnet-name myVNet \
79+
--address-prefixes 10.1.1.0/27
80+
```
81+
82+
### Create the bastion host
83+
84+
Use [az network bastion create](/cli/azure/network/bastion#az_network_bastion_create) to create a host.
85+
86+
```azurecli
87+
az network bastion create \
88+
--resource-group CreateIntLBQS-rg \
89+
--name myBastionHost \
90+
--public-ip-address myBastionIP \
91+
--vnet-name myVNet \
92+
--location westus3
93+
```
94+
95+
It can take a few minutes for the Azure Bastion host to deploy.
96+
97+
## Create the load balancer
98+
99+
This section details how you can create and configure the following components of the load balancer:
100+
101+
* A frontend IP pool that receives the incoming network traffic on the load balancer
102+
103+
* A backend IP pool where the frontend pool sends the load balanced network traffic
104+
105+
* A health probe that determines health of the backend VM instances
106+
107+
* A load balancer rule that defines how traffic is distributed to the VMs
108+
109+
### Create the load balancer resource
110+
111+
Create an internal load balancer with [az network lb create](/cli/azure/network/lb#az_network_lb_create).
112+
113+
```azurecli
114+
az network lb create \
115+
--resource-group CreateIntLBQS-rg \
116+
--name myLoadBalancer \
117+
--sku Basic \
118+
--vnet-name myVNet \
119+
--subnet myBackendSubnet \
120+
--frontend-ip-name myFrontEnd \
121+
--backend-pool-name myBackEndPool
122+
```
123+
124+
### Create the health probe
125+
126+
A health probe checks all virtual machine instances to ensure they can send network traffic.
127+
128+
A virtual machine with a failed probe check is removed from the load balancer. The virtual machine is added back into the load balancer when the failure is resolved.
129+
130+
Create a health probe with [az network lb probe create](/cli/azure/network/lb/probe#az_network_lb_probe_create).
131+
132+
```azurecli
133+
az network lb probe create \
134+
--resource-group CreateIntLBQS-rg \
135+
--lb-name myLoadBalancer \
136+
--name myHealthProbe \
137+
--protocol tcp \
138+
--port 80
139+
```
140+
141+
### Create a load balancer rule
142+
143+
A load balancer rule defines:
144+
145+
* Frontend IP configuration for the incoming traffic
146+
147+
* The backend IP pool to receive the traffic
148+
149+
* The required source and destination port
150+
151+
Create a load balancer rule with [az network lb rule create](/cli/azure/network/lb/rule#az_network_lb_rule_create).
152+
153+
```azurecli
154+
az network lb rule create \
155+
--resource-group CreateIntLBQS-rg \
156+
--lb-name myLoadBalancer \
157+
--name myHTTPRule \
158+
--protocol tcp \
159+
--frontend-port 80 \
160+
--backend-port 80 \
161+
--frontend-ip-name myFrontEnd \
162+
--backend-pool-name myBackEndPool \
163+
--probe-name myHealthProbe \
164+
--idle-timeout 15
165+
```
166+
167+
## Create a network security group
168+
169+
For a standard load balancer, the VMs in the backend pool are required to have network interfaces that belong to a network security group.
170+
171+
To create a network security group, use [az network nsg create](/cli/azure/network/nsg#az_network_nsg_create).
172+
173+
```azurecli
174+
az network nsg create \
175+
--resource-group CreateIntLBQS-rg \
176+
--name myNSG
177+
```
178+
179+
## Create a network security group rule
180+
181+
To create a network security group rule, use [az network nsg rule create](/cli/azure/network/nsg/rule#az_network_nsg_rule_create).
182+
183+
```azurecli
184+
az network nsg rule create \
185+
--resource-group CreateIntLBQS-rg \
186+
--nsg-name myNSG \
187+
--name myNSGRuleHTTP \
188+
--protocol '*' \
189+
--direction inbound \
190+
--source-address-prefix '*' \
191+
--source-port-range '*' \
192+
--destination-address-prefix '*' \
193+
--destination-port-range 80 \
194+
--access allow \
195+
--priority 200
196+
```
197+
198+
## Create back-end servers
199+
200+
In this section, you create:
201+
202+
* Two network interfaces for the virtual machines
203+
204+
* Two virtual machines to be used as servers for the load balancer
205+
206+
### Create network interfaces for the virtual machines
207+
208+
Create two network interfaces with [az network nic create](/cli/azure/network/nic#az_network_nic_create).
209+
210+
```azurecli
211+
array=(myNicVM1 myNicVM2)
212+
for vmnic in "${array[@]}"
213+
do
214+
az network nic create \
215+
--resource-group CreateIntLBQS-rg \
216+
--name $vmnic \
217+
--vnet-name myVNet \
218+
--subnet myBackEndSubnet \
219+
--network-security-group myNSG
220+
done
221+
```
222+
223+
### Create the availability set for the virtual machines
224+
225+
Create the availability set with [az vm availability-set create](/cli/azure/vm/availability-set#az_vm_availability_set_create).
226+
227+
```azurecli
228+
az vm availability-set create \
229+
--name myAvailabilitySet \
230+
--resource-group CreateIntLBQS-rg \
231+
--location westus3
232+
```
233+
234+
### Create the virtual machines
235+
236+
Create the virtual machines with [az vm create](/cli/azure/vm#az_vm_create).
237+
238+
```azurecli
239+
array=(1 2)
240+
for n in "${array[@]}"
241+
do
242+
az vm create \
243+
--resource-group CreateIntLBQS-rg \
244+
--name myVM$n \
245+
--nics myNicVM$n \
246+
--image win2019datacenter \
247+
--admin-username azureuser \
248+
--availability-set myAvailabilitySet \
249+
--no-wait
250+
done
251+
```
252+
253+
It can take a few minutes for the VMs to deploy.
254+
255+
[!INCLUDE [ephemeral-ip-note.md](../../../includes/ephemeral-ip-note.md)]
256+
257+
## Add virtual machines to the backend pool
258+
259+
Add the virtual machines to the backend pool with [az network nic ip-config address-pool add](/cli/azure/network/nic/ip-config/address-pool#az_network_nic_ip_config_address_pool_add).
260+
261+
```azurecli
262+
array=(VM1 VM2)
263+
for vm in "${array[@]}"
264+
do
265+
az network nic ip-config address-pool add \
266+
--address-pool myBackendPool \
267+
--ip-config-name ipconfig1 \
268+
--nic-name myNic$vm \
269+
--resource-group CreateIntLBQS-rg \
270+
--lb-name myLoadBalancer
271+
done
272+
273+
```
274+
275+
## Create test virtual machine
276+
277+
Create the network interface with [az network nic create](/cli/azure/network/nic#az_network_nic_create).
278+
279+
```azurecli
280+
az network nic create \
281+
--resource-group CreateIntLBQS-rg \
282+
--name myNicTestVM \
283+
--vnet-name myVNet \
284+
--subnet myBackEndSubnet \
285+
--network-security-group myNSG
286+
```
287+
Create the virtual machine with [az vm create](/cli/azure/vm#az_vm_create).
288+
289+
```azurecli
290+
az vm create \
291+
--resource-group CreateIntLBQS-rg \
292+
--name myTestVM \
293+
--nics myNicTestVM \
294+
--image Win2019Datacenter \
295+
--admin-username azureuser \
296+
--no-wait
297+
```
298+
You might need to wait a few minutes for the virtual machine to deploy.
299+
300+
## Install IIS
301+
302+
Use [az vm extension set](/cli/azure/vm/extension#az_vm_extension_set) to install IIS on the backend virtual machines and set the default website to the computer name.
303+
304+
```azurecli
305+
array=(myVM1 myVM2)
306+
for vm in "${array[@]}"
307+
do
308+
az vm extension set \
309+
--publisher Microsoft.Compute \
310+
--version 1.8 \
311+
--name CustomScriptExtension \
312+
--vm-name $vm \
313+
--resource-group CreateIntLBQS-rg \
314+
--settings '{"commandToExecute":"powershell Add-WindowsFeature Web-Server; powershell Add-Content -Path \"C:\\inetpub\\wwwroot\\Default.htm\" -Value $($env:computername)"}'
315+
done
316+
317+
```
318+
319+
## Test the load balancer
320+
321+
1. [Sign in](https://portal.azure.com) to the Azure portal.
322+
323+
2. On the **Overview** page, find the private IP address for the load balancer. In the menu on the left, select **All services** > **All resources** > **myLoadBalancer**.
324+
325+
3. In the overview of **myLoadBalancer**, copy the address next to **Private IP Address**. If **Private IP address** isn't visible, select **See more**.
326+
327+
4. In the menu on the left, select **All services** > **All resources**. From the resources list, in the **CreateIntLBQS-rg** resource group, select **myTestVM**.
328+
329+
5. On the **Overview** page, select **Connect** > **Bastion**.
330+
331+
6. Enter the username and password that you entered when you created the VM.
332+
333+
7. On **myTestVM**, open **Internet Explorer**.
334+
335+
8. Enter the IP address from the previous step into the address bar of the browser. The default page of the IIS web server is shown in the browser.
336+
337+
## Clean up resources
338+
339+
When your resources are no longer needed, use the [az group delete](/cli/azure/group#az-group-delete) command to remove the resource group, load balancer, and all related resources.
340+
341+
```azurecli
342+
az group delete \
343+
--name CreateIntLBQS-rg
344+
```
345+
346+
## Next steps
347+
348+
In this quickstart:
349+
350+
* You created an internal basic load balancer
351+
352+
* Attached two virtual machines
353+
354+
* Configured the load balancer traffic rule and health probe
355+
356+
* Tested the load balancer
357+
358+
To learn more about Azure Load Balancer, continue to:
359+
> [!div class="nextstepaction"]
360+
> [What is Azure Load Balancer?](../load-balancer-overview.md)

articles/load-balancer/basic/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ items:
1515
items:
1616
- name: Portal
1717
href: quickstart-basic-internal-load-balancer-portal.md
18+
- name: CLI
19+
href: quickstart-basic-internal-load-balancer-cli.md
1820
- name: Reference
1921
items:
2022
- name: Azure CLI

articles/load-balancer/quickstart-load-balancer-standard-internal-cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ This section details how you can create and configure the following components o
108108

109109
### Create the load balancer resource
110110

111-
Create a public load balancer with [az network lb create](/cli/azure/network/lb#az_network_lb_create).
111+
Create an internal load balancer with [az network lb create](/cli/azure/network/lb#az_network_lb_create).
112112

113113
```azurecli
114114
az network lb create \

0 commit comments

Comments
 (0)