Azure Availability Set
Ankit Ranjan (DevOps Engineer)
Actively Seeking Full-time Azure DevOps/Azure Cloud Engineer Opportunities | Certified Terraform Associate | IAM-Azure DevOps Engineer | Ebug India
Create a load balancer with more than one availability set in the backend pool using the Azure portal
As part of a high-availability deployment, virtual machines are typically organized into multiple availability sets to ensure redundancy.
Azure Load Balancer allows the inclusion of virtual machines from multiple availability sets within its backend pool.
In this guide, you'll learn how to:
Prerequisites:
An active Azure account with a valid subscription. If you don't have one, you can [create a free account]
Create NAT Gateway
This section walks you through creating a NAT gateway, providing outbound internet access for resources in your virtual network. For alternative outbound connection options, explore Network Address Translation (SNAT) for outbound connections.
1. Sign in to the Azure portal.
2. In the search box at the top, type NAT gateway and select NAT gateways from the search results.
3. Click on + Create to start creating a new NAT gateway.
4. Enter or select the required information on the?Basics?tab of the "Create network address translation (NAT) gateway" page.
5. Navigate to the Outbound IP tab, or click Next: Outbound IP at the bottom of the page.
6. Under Public IP addresses, choose Create a new public IP address.
7. In the Add a Public IP address dialog, enter nat-gw-public-ip in the Name field.
8. Click OK.
9. Select the blue Review + Create button at the bottom of the page, or go to the Review + Create tab.
10. Finally, click Create to complete the process.
Create a Virtual Network
Follow these steps to create a virtual network with a resource subnet:
1. In the Azure portal, search for and select Virtual networks.
2. On the Virtual Networks page, click + Create to begin.
3. Provide the necessary information in the?Basics?tab of the "Create virtual network" page.
4. Select the IP Addresses tab, or click Next: Security followed by Next: IP Addresses at the bottom of the page.
5. In the Address space section, choose the default subnet.
6. Enter the required details in the Edit subnet dialog and click Save.
7. Select Review + Create at the bottom of the page, and once the validation succeeds, click Create to finalize.
Create a Network Security Group
In this section, you'll create a Network Security Group (NSG) for the virtual machines in the backend pool of the load balancer, allowing inbound traffic on port 80.
1. In the Azure portal, use the search box to type Network security group and select Network security groups from the results.
2. Click on + Create or Create a network security group to begin.
3. In the Basics tab, provide the necessary information.
4. Click on the Review + Create tab, or select the blue Review + Create button at the bottom of the page.
5. Click Create to initiate the deployment.
6. Once deployment is complete, click Go to the resource.
7. On the lb-NSG resource page, navigate to the Settings section and select Inbound security rules.
8. Click + Add to create a new inbound security rule.
9. In the Add inbound security rule window, provide the required information.
10. Select Add.
Create a Load Balancer
Follow these steps to create a load balancer for your virtual machines:
1. In the Azure portal, use the search box to type Load balancer and select Load balancers from the results.
2. On the Load balancers page, click Create or Create load balancer to start.
3. In the Basics tab of the "Create load balancer" page, fill in the necessary information.
4. Go to the Frontend IP configuration tab, or click Next: Frontend IP configuration at the bottom of the page.
5. In the Frontend IP configuration section, click + Add a Frontend IP configuration.
6. Enter lb-frontend-IP for the Name.
7. Choose IPv4 or IPv6 for the IP version, and select the IP address for the IP type. Then, click Create New under Public IP address.
8. In the Add a Public IP address dialog, enter lb-public-IP for the Name, choose Zone-redundant for the Availability zone, and click OK.
9. Click Add to confirm the configuration.
10. Select Next: Backend pools at the bottom of the page.
11. On the Backend pools tab, click + Add a backend pool.
12. Enter lb-backend-pool for the Name and select lb-VNet for the Virtual network.
13. For Backend Pool Configuration, select IP Address and click Save.
14. Move to the Inbound rules tab by selecting it or clicking Next: Inbound rules.
15. In the Inbound rules tab, click + Add a load balancing rule.
16. In the Add load balancing rule dialog, enter the required information and click Save.
17. Click the blue Review + Create button at the bottom of the page.
18. Finally, click Create to deploy the load balancer.
Create Virtual Machines
In this section, you'll create two availability sets, each containing two virtual machines. These virtual machines will be added to the backend pool of the load balancer during their creation.
Create the First Set of VMs:
1. In the Azure portal, select + Create a resource from the top-left corner.
2. On the New page, go to Compute and select Virtual Machine.
3. In the Basics tab of the "Create a virtual machine" page, enter the required information.
4. Click on the Networking tab, or select Next: Disks and then Next: Networking at the bottom of the page.
5. In the Networking tab, provide the necessary details.
6. Select the Review + Create tab, or click the blue Review + Create button at the bottom.
7. Click Create to deploy the virtual machine.
8. Repeat steps 1 through 7 to create the second virtual machine in the set, adjusting the settings as needed for this VM.
Create the Second Set of VMs
1. In the Azure portal, click + Create a resource in the top-left corner.
2. Navigate to Compute and select Virtual machine.
3. In the Basics tab of the "Create a virtual machine" page, provide the necessary details.
4. Click the Networking tab, or select Next: Disks and then Next: Networking at the bottom of the page.
5. In the Networking tab, enter the required information.
6. Select the Review + Create tab, or click the blue Review + Create button at the bottom.
7. Click Create to deploy the virtual machine.
8. Repeat steps 1 through 7 to create the second virtual machine in this set, updating the settings for the new VM as required.
Install IIS
In this section, you'll connect to the virtual machines using the previously created Azure Bastion host and install IIS.
1. In the Azure portal, use the search box to type Virtual machine and select Virtual machines from the search results.
2. Choose lb-VM1 from the list.
3. In the left-hand menu under Operations, select Run command > RunPowerShellScript.
4. In the PowerShell Script window, enter the following commands to:
- Install the IIS server
- Remove the default iisstart.htm file
- Add a new iisstart.htm file to display the VM's name:
Install IIS server role
Install-WindowsFeature -name Web-Server -IncludeManagementTools
Remove the default htm file
Remove-Item C:\inetpub\wwwroot\iisstart.htm
Add a new htm file that displays the server name
Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
5. Select Run and wait for the command to complete.
Output
6. Repeat steps 1 through 8 for lb-VM2, lb-VM3, and lb-VM4.
Test the Load Balancer
In this section, you'll find the public IP address of the load balancer and use it to verify its operation.
1. In the Azure portal, type Public IP into the search box and select Public IP addresses from the search results.
2. Click on lb-Public-IP.
领英推荐
3. On the Overview page of lb-Public-IP, take note of the public IP address listed under the IP address section.
4. Open a web browser and enter the public IP address in the address bar.
5. Refresh the browser to observe how traffic is balanced across the virtual machines in the backend pool.
Clean Up Resources
If you no longer plan to use this application, follow these steps to delete the load balancer and its supporting resources:
1. In the Azure portal, enter Resource group in the search box and select Resource groups from the results.
2. Click on lb-resource-group.
3. On the Overview page of lb-resource-group, select Delete resource group.
4. Check the option for Apply force delete for the selected Virtual Machines and Virtual Machine Scale Sets.
5. In the confirmation prompt, enter lb-resource-group to confirm the deletion.
6. Click Delete to finalize the process.
In this tutorial, you have:
Load balance VMs within an availability zone by using the Azure portal
This tutorial guides you through the process of creating a public load balancer with a zonal IP address. You will specify a zone for both your frontend and backend instances.
In this tutorial, you will learn how to:
Prerequisites
An Azure subscription - Access to the Azure portal
Create a Virtual Network and Bastion Host
In this section, you will create a virtual network that includes a resource subnet, an Azure Bastion subnet, and an Azure Bastion host. Follow these steps:
1. In the Azure portal, search for and select Virtual networks.
2. On the Virtual Networks page, click + Create.
3. In the Basics tab of the "Create virtual network" page, enter or select the necessary information.
4. Navigate to the Security tab or click the Next button at the bottom of the page.
5. Under the Azure Bastion section, provide the required information, then go to the IP addresses tab or click Next at the bottom.
6. On the Create Virtual Network page, enter or select the necessary information.
7. Click Save.
8. Select Review + Create at the bottom of the screen, and once validation is successful, click Create.
Create NAT Gateway
In this section, you'll create a NAT gateway to provide outbound internet access for resources within the virtual network. For additional options regarding outbound rules, refer to Network Address Translation (SNAT) for outbound connections.
1. Sign in to the Azure portal.
2. In the search box at the top of the portal, type NAT gateway and select NAT gateways from the search results.
3. Click + Create.
4. In the Basics tab of the "Create network address translation (NAT) gateway" page, enter or select the required information.
5. Navigate to the Outbound IP tab, or click the Next: Outbound IP button at the bottom of the page.
6. Under Public IP addresses, select Create a new public IP address.
7. In the Add a Public IP address section, enter nat-gw-public-ip in the Name field.
8. Click OK.
9. Go to the Subnet tab or click the Next: Subnet button at the bottom of the page.
10. On the Subnet page, select lb-vnet from the Virtual network dropdown menu.
11. For the Subnet name, choose the backend subnet.
12. Click the blue Review + Create button at the bottom of the page or navigate to the Review + Create tab.
13. Select Create to finalize the process.
Create Load Balancer
In this section, you will create a load balancer for the virtual machines.
1. In the Azure portal, type Load balancer in the search box and select Load balancers from the search results.
2. On the Load balancer page, click Create or the Create load balancer button.
3. In the Basics tab of the "Create load balancer" page, enter or select the required information.
4. Navigate to the Frontend IP configuration tab or click the Next: Frontend IP configuration button at the bottom of the page.
5. In the Frontend IP configuration section, click + Add a Frontend IP configuration.
6. Enter lb-frontend-IP in the Name field.
7. Choose either IPv4 or IPv6 for the IP version. Select the IP address for the IP type, and choose Create New under Public IP address.
8. In the Add a public IP address section, enter lb-public-IP in the Name field.
9. Select Zone-redundant for the Availability zone and click OK.
10. Click Add to finalize the frontend IP configuration.
11. Select the Next: Backend pools button at the bottom of the page.
12. In the Backend Pools tab, click + Add a Backend Pool.
13. Enter lb-backend-pool in the Name field for the backend pool.
14. From the Virtual network dropdown, select lb-VNet.
15. For Backend Pool Configuration, select IP Address and then click Save.
16. Navigate to the Inbound rules tab or click the Next: Inbound rules button at the bottom.
17. In the Inbound rules tab, click + Add a load balancing rule.
18. In the Add load balancing rule section, enter or select the required information and click Save.
19. Finally, select the blue Review + Create button at the bottom of the page.
20. Click Create to complete the setup.
Create Virtual Machines
In this section, you will create two virtual machines (lb-vm1 and lb-vm2) within a single zone (Zone 1). These VMs will be added to the backend pool of the previously created load balancer.
1. In the Azure portal, type Virtual machine in the search box and select Virtual machines from the search results.
2. In the Virtual Machines section, click + Create and then select Azure virtual machine.
3. In the Create a Virtual Machine pane, enter or select the required values in the Basics tab.
4. Next, navigate to the Networking tab, or click Next: Disks, followed by Next: Networking.
5. In the Networking tab, select or enter the necessary information.
6. Click Review + create to proceed.
7. Review the settings and then click Create to deploy the VM.
8. Repeat steps 1 through 7 to create the second VM, ensuring that all settings are identical to those of lb-vm1, except for the name.
Install IIS
1. In the left-hand menu, select All Services and then choose All Resources. From the list of resources, locate and select lb-VM1 within the load-balancer-rg resource group.
2. On the Overview page, click Connect, then select Bastion.
3. Choose Use Bastion.
4. Enter the username and password you specified during the VM creation process.
5. Click Connect.
6. Once on the server desktop, navigate to Windows Administrative Tools and select Windows PowerShell.
7. In the PowerShell window, execute the following commands:
- Install the IIS server
- Remove the default iisstart.htm file
- Add a new iisstart.htm file that displays the name of the VM:
Install IIS server role
Install-WindowsFeature -name Web-Server -IncludeManagementTools
Remove the default htm file
Remove-Item C:\inetpub\wwwroot\iisstart.htm
Add a new htm file that displays the server name
Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
8. Close the Bastion session with lb-VM1.
9. Repeat steps to install IIS and the updated iisstart.htm file on lb-VM2.
Test the Load Balancer
1. In the search box at the top of the page, type Load balancer and select Load balancers from the search results.
2. Click on the load balancer you created, named load-balancer.
3. On the Frontend IP configuration page of your load balancer, find the public IP address.
4. Copy the public IP address and paste it into the address bar of your web browser. This should display the custom VM page of the IIS web server.
Clean Up Resources
When you no longer need the resources, delete the resource group, load balancer, and all associated resources. To do this, select the resource group load-balancer-rg that contains the resources, then click on Delete.
Azure Cloud Engineer | DevOps | SRE
3 周Very informative
Software Developer
1 个月Hi Ankit, How do I ensure the vm availability of particular image before creation and many times I encounter problem in iis installation issue after creation of vm. how to know that vm has problem.