Getting Started: Setting up an Azure Availability Set

choubertsprojects

VPN offers!

1. NordVPN

2. Surfshark

3. ExpressVPN

Azure Availability Sets allow users to span across multiple Azure regions with a single point of control and management. This article walks you through setting up an Availability Set, choosing the locations for your VMs, configuring network settings on each node, and then applying tags so they can be easily referenced in scripts or monitoring tools.

The “how to add existing vm to availability set azure” is a tutorial that will help you get started with Azure Availability Sets. This tutorial will walk you through the process of setting up an Azure Availability Set, and adding your existing VM to it.

Getting Started: Setting up an Azure Availability Set

An IT professional’s most crucial task is to keep a program operating. When it comes to doing their jobs or using your service, people rely on dependability and availability. Take a look at Azure availability settings to get the most out of your virtual machines.

You’ll learn about Azure availability settings and the advantages of utilizing them with your virtual machines in this lesson. You’ll also learn how to use PowerShell, Azure CLI, and Terraform to deploy availability settings. So, if you’re up for it, let’s get started!

What is an Availability Set in Azure?

Azure availability settings join your virtual machines (VMs) together logically. These classifications help Azure identify how you constructed your virtual machine-based application. Azure can then better manage virtual machines, offer redundancy, and increase availability.

If you want to deploy a highly available application, Microsoft advises creating an availability set with two or more virtual machines. You may reach Azure’s 99.95 percent uptime service-level agreement by adding two additional VMs to an availability set (SLA). Fortunately, you can utilize availability settings for free! Only the virtual machines that are generated are charged for.

Update Domains protect VMs against host reboots.

Virtual machines in Azure are similar to virtual machines on-premises in that they share a single physical host server. The physical host server and virtual machines that Azure may concurrently reboot are represented by an update domain.

Consider an application that is distributed over three virtual machines. Those three virtual machines should not share a single host server. If the host server fails, all three virtual machines become unavailable, and the application becomes unavailable. This issue is solved by using an update domain.

Azure will automatically deploy VMs into distinct update domains when you link them with an availability set. Multiple virtual machines cannot go down because an availability set divides them into distinct domains. When Azure does maintenance or the host fails, update domains keep virtual machines running.

Azure may reboot and update domains in any order during scheduled maintenance. However, Azure promises that only one update domain will be rebooted at a time. During maintenance, Azure provides a restarted update domain 30 minutes to recover before switching to the next update domain.

Up to 20 update domains are allowed in availability sets. The figure below shows how Azure distributes three virtual machines (VM1, VM2, and VM3) over two server racks into three update domains.

Three virtual computers, each with its own update domainThree virtual computers, each with its own update domain

Using Fault Domains to Prevent VM Outages

When a server rack where your VM is housed loses power, creating physical issues, the VM will generally go offline; fault domains prevent this. A failure domain is a collection of virtual computers that share the same hardware. A failure domain in Azure is a single rack with numerous servers deployed.

In an availability set, Azure distributes virtual machines across up to three fault domains. VM2 and VM3 are housed in Server Rack 2 according to the update domain diagram from the previous section. For genuine application high availability, VM3 should be in a distinct failure domain, as shown below.

Three virtual machines are distributed across three fault domains.Three virtual machines are distributed across three fault domains.

Azure mitigates the effect of hardware failures on host servers and virtual machines by putting each virtual machine in its own server rack (or fault domain).

Azure also associates virtual machines with disk failure domains to guarantee that managed disks are shared across virtual machines.

You’ll create an availability set in a future lesson, and a snapshot of the availability set from the Azure Portal is shown below. Three fault domains, three update domains, and three virtual machines make up the availability set you create. Each virtual machine is automatically distributed throughout the three update domains and fault domains by Azure (0, 1, and 2).

Availability Display three virtual machines across fault domains and update domains in Azure Portal.Availability Display three virtual machines across fault domains and update domains in Azure Portal.

Best Practices for Availability

Here are some recommended practices for making the most of availability sets.

  • Prior to constructing virtual machines, create the availability set. To support the virtual machine workload, plan out the appropriate fault domains and update domains.
  • When building a virtual machine, provide the availability set. After Azure has provisioned a virtual machine, it is not possible to add it to an availability set. If you need to add an existing virtual machine to an availability set, you must redeploy it.
  • Separate availability settings for virtual machines with comparable tasks. If you have a three-tier application, for example, each tier’s virtual machines should be in their own availability set.
  • For virtual computers, use managed drives. Managed drives improve the resilience of virtual machines in an availability set. To avoid single points of failure, the managed disks are segregated from one another.

Creating and Deploying Virtual Machines in an Availability Set is a tutorial.

Now that you’ve learned about the ideas of an availability set, it’s time to construct one and deploy virtual machines to it! Choose your chosen deployment technique from the options shown in this lesson. All resources are deployed to a resource group called avsetdemo-rg in Azure region WestUS2 throughout the lesson.

This article shows how to deploy a three-tier application with a web front-end, a middle application, and a database back-end. Let’s get started!

Azure CLI

Because you’ll be executing commands in a command-line environment throughout this lesson, let’s start with Azure CLI. To host the web layer of virtual machines, you’ll use Azure CLI to create an availability set. Virtual machines that perform the same task should be in the same availability set.

With the help of a PowerShell loop, you’ll construct three virtual machines and add them to the availability set.

Getting Started with the Azure CLI is related.

Prerequisites

Please make sure you have the following materials in order to follow along with this tutorial:

  • Azure CLI 2.0.30 or later is required. v2.25.0 is used in this lesson.
  • Windows PowerShell v5.1 (default on Windows 10) or PowerShell v7.0 or above is required. PowerShell v7.1.3 is used in this lesson.

Now that you have Azure CLI and PowerShell installed, you can begin constructing an availability set by following the steps below.

1. Switch to the PowerShell console.

2. Use the az login command to access your Azure environment.

3. Create the availability first, then the virtual machines. Before you can add VMs to an availability set, it must first exist.

The az vm availability-set create command creates an availability set. The resource-group (avsetdemo-rg), the availability set name (avset-web), and the platform-fault-domain-count and platform-update-domain-count counts must all be specified (3 each).

When the command is finished, you’ll have an availability set with three fault domains and three update domains, as well as the possibility to add some VMs!

—resource-group az vm availability-set create —name avsetdemo-rg —platform-update-domain-count 3 —platform-fault-domain-count 3 avset-web

Using Azure CLI to create an availability setUsing Azure CLI to create an availability set

4. Create a variable ($webVMs) with the names of the web front-end servers (‘web01′,’web02′,’web03’). When you create the virtual machines in the following phase, you’ll utilize these names.

@(‘web01′,’web02′,’web03’) $webVMs

5. Create numerous virtual machines by looping (foreach) over each name in $webVMs. The az vm create command is used to build virtual machines. You can only add VMs to an availability set after they’ve been created, so make sure you do it immediately!

The example below uses the current value in $vm to provide the virtual machine name and creates it in the resource-group avsetdemo-rg. Using the avset-web name, configure the virtual machine to join the availability-set.

The size (Standard DS1 v2) and operating system image are the only remaining virtual machine parameters (UbuntuLTS). The network subnet is snet-web, and the virtual machine’s vnet-name is vnet-app. Finally, change the admin-username to cloudadmin and produce SSH keys for login in using generate-ssh-keys.

($vm in $webVMs) foreach —name $vm —resource-group az vm create —availability-set avsetdemo-rg —image UbuntuLTS —vnet-name vnet-app —subnet avset-web —size Standard DS1 v2 —generate-ssh-keys snet-web —admin-username cloudadmin

PowerShell in Azure

Creating an availability set using PowerShell in Azure is similar to how you’ve done in it Azure CLI. However, PowerShell in Azure requires an extra step of creating an administrator username and password. After you created an availability set, you’ll then create three virtual machines for the app tier with a PowerShell loop and place each virtual machine into the availability set.

Prerequisites

Please make sure you have the following materials in order to follow along with this tutorial:

Now that you have PowerShell in Azure Module and PowerShell console ready, follow the steps below and start creating an availability set!

1. Start a PowerShell session.

2. Use the Connect-AzAccount command to connect to your Azure environment.

3. Create the availability first, then the virtual machines. Before you can add VMs to an availability set, it must first exist.

Run the New-AzAvailabilitySet command with the name avset-app to create an availability set. In the Location of WestUS2, the command below provides a ResourceGroupName (avsetdemo-rg).

Set the Sku parameter to aligned to configure the availability set for managed drives. Managed drives improve the resilience of virtual machines in an availability set. Finally, each PlatformFaultDomainCount and PlatformUpdateDomainCount should be set to three counts.

When the New-AzAvailabilitySet command is finished, a new availability set named avset-app will be established in the avsetdemo-rg resource group, employing managed disks and three fault and update domains.

-Name “avset-app” -ResourceGroupName “avsetdemo-rg” -Location “WestUS2” New-AzAvailabilitySet -PlatformFaultDomainCount 3 -PlatformUpdateDomainCount 3 -Sku aligned

Create an availability set using PowerShell in AzureCreate an availability set using PowerShell in Azure

4. Create a variable called $appVMs that has a list of application server names (‘app01,”app02,’app03’). When you create the virtual machines in the following phase, you’ll utilize these names.

@(‘app01′,’app02′,’app03’) $appVMs

5. Run Get-Credential to create a PowerShell credential object, then store the credentials to a variable called $creds. Enter a username and password when asked. This credential object will be used later to establish the virtual machine administrator’s username and password.

6. Run New-AzVM for each of the VM names specified in the $appVMs array in a loop (foreach). Using the New-AzVM command, the examples below build numerous virtual machines and supply them. You can only add VMs to an availability set after they’ve been created, so make sure you do it immediately!

The New-AzVM command builds a virtual machine in the avsetdemo-rg resource group with the virtual machine Name set to the current value in $vm. The virtual machine is then configured to join the avset-app availability set.

The Size (Standard DS1 v2) and operating system Image are the only remaining virtual machine parameters (UbuntuLTS). vnet-app is the VirtualNetworkName of the virtual machine, and snet-app is the network SubnetName. Finally, configure the virtual machine Credential login using the $creds credential object you prepared previously.

($vm in $appVMs) foreach -Location “WestUS2” -AvailabilitySetName “avset-app” -Size “Standard DS1 v2” -VirtualNetworkName “vnet-app” -SubnetName “snet-app” -Image UbuntuLTS -Credential $creds }

Terraform

Creating an availability set and virtual machines using Terraform is a bit different from Azure CLI and PowerShell in Azure. With Terraform, you do not run individual commands to build the resource components. Instead, you define the resource properties and Terraform provisions the infrastructure for you.

What Does an Infrastructure Developer Do?

This lesson assumes you’re familiar with Terraform, including how to use resource providers and define resources. Check see Getting Started with Terraform on Windows: Install, Setup, and Demo if you’re new to Terraform.

Prerequisites

Please make sure you have the following materials in order to follow along with this tutorial:

  • Terraform binary in its most recent version.
  • Windows PowerShell v5.1 (default on Windows 10) or PowerShell v7.0 or above is required. PowerShell v7.1.3 is used in this lesson.

Follow the instructions below to create an availability set now that you have the Terraform binaries and PowerShell console.

1. Use the az login command to log into your Azure environment, same as you did in the Azure CLI section.

2. Create a main.tf Terraform configuration file. Use your preferred code editor to open this file.

3. Create an azurerm availability set resource definition in the main.tf configuration file.

The availability set name (avset-db) is included in the resource specification, which sets the platform fault domain count and platform update domain count attributes to three each. To specify the availability set for managed disks, set the managed attribute to true.

The resource group avsetdemo-rg is created in the location westus2 in the example below. You use dependencies to indicate where to position the availability group when establishing the availability set. The resource group name (azurerm resource group.rg.name) and location (azurerm resource group.rg.location) both reflect this.

Examples of Using Terraform Resource Dependencies with Azure

name = “avsetdemo-rg” location = “westus2” resource “azurerm resource group” “rg” name = “avset-db” resource “azurerm availability set” “avset-db” platform fault domain count = 3 platform update domain count = 3 managed = true resource group name = azurerm resource group.rg.name location = azurerm resource group.rg.location

4. Use the availability set id option to indicate the avset-db availability set when defining the virtual machine resource. The value uses the resource type (azurerm availability set), symbolic name (avset-db), and property id to refer to the Terraform resource. Consider the following example of a virtual machine argument.

# Remaining properties… resource “azurerm linux virtual machine” “vm” availability set id = azurerm availability set.avset-db.id

The ATA GitHub repository has an example Terraform setup that illustrates deploying availability sets and virtual machines.

Unlike the previous approaches in this lesson, the ATA GitHub repository’s configuration file establishes the virtual network and subnet. When building the network interface and virtual machines, this setting is required to leverage resource references and dependencies.

How to Build with Terraform: Azure Virtual Machines (Windows)

5. Finally, return to your PowerShell console and deploy the Terraform configuration. Begin the deployment by establishing a deployment strategy and initializing the appropriate providers (terraform init) (terraform plan -out deploy.tfplan). Then put the proposed arrangement into action (terraform apply deploy.tfplan).

Perform a destroy operation (terraform destroy) to eliminate the environment after reviewing the deployed resources.

# Create a deployment plan called deploy using the terraform init command. terraform plan -out deploy tfplan tfplan # Use the deploy command to deploy the resources. terraform apply deploy tfplan file tfplan # Terraform and destroy the resources

Conclusion

In this tutorial, you learned about the benefits of Azure availability sets for your virtual machines in maximizing uptime and availability. You then created availability sets using three different methods: the Azure CLI, PowerShell in Azure, and Terraform.

Make sure to incorporate availability settings in your next Azure virtual machine deployment now that you have this new knowledge and deployment abilities!

The “create availability set in azure portal” is a step-by-step guide on how to set up an Azure Availability Set.

Related Tags

  • azure availability set vs zone
  • azure availability set single vm
  • is it possible to add an existing vm to an availability set in azure
  • azure availability set update domain
  • azure availability set vs scale set