In this chapter, you’ll move beyond your basic physical Windows server (even if it hosts several virtual machines!) and explore the cloud in detail. Microsoft’s public cloud is called Azure. Like Amazon, Google, or even OVH clouds, it lets you create virtual machine-like instances—on a server that doesn’t belong to you.
What Is Azure?
In addition to simple instances, Microsoft’s cloud service (Azure) offers a whole ecosystem of hosted services managed (more or less) by Microsoft’s teams.
Two Key Characteristics:
It is hosted and managed by a third party.
It’s pay per use, so you only pay for what you need. For example, why pay more if you only need a processor or another 10 GB of storage?
With the cloud, you can be in charge of what you consume and often save compared to buying all your own infrastructure.
Get Started With Azure
To get started with Azure, you must first create an account. Usually, like with all providers of this type, you’ll be entitled to a voucher for using the services, which lets you try them out for free.
Once you’ve created your account, you’ll have access to the Azure portal dashboard. It lists your available options on the left-hand menu and gives you an overview of your resources on the rest of the screen:
There’s a Quickstart Center sidebar containing two options:
Start a project (e.g., create a web app, deploy a virtual machine).
Take an online course.
Both of these are good places to start your Azure journey. The one you choose first will depend on your requirements.
Create Your First Cloud Instance
On the portal, from the left-hand menu, select Virtual Machines. You’ll see a new window for adding an instance. Select Create, Azure virtual machine, and you’ll get a settings screen with seven different tabs for detailing the features of your virtual machine (Basics, Disks, Networking, Management, Guest config, Tags, Review + create).
The first tab is the basics tab, which allows you to set such options as selecting the subscription you’ll use for creating your machine. We’ll stick to the free subscription here.
After selecting the subscription, you need to define a resource group (a group of resources with an identical objective).
Next, enter the name of the virtual machine. Again, consistent naming helps you search for and identify your instance. Azure will also ask you for a region, the data center in which your virtual machine will be provisioned. It could be in any of the 54 data centers that Microsoft currently manages.
After choosing the location, you’ll be able to define the level of availability of your virtual machine.
You have four options for the level of availability:
No infrastructure redundancy is required (no high availability).
Availability zone.
Virtual machine scale set.
Availability set.
These options let you create an application with guaranteed availability by Microsoft (provided you follow best practices). Here’s what these options mean:
An availability zone is an isolated zone of the error domain in an Azure region that provides redundant power, cooling, and networking.
A virtual machine scale set is the number of VM instances that can automatically increase or decrease in response to demand or a defined schedule.
An availability set is a logical grouping of VMs that allows Azure to understand how your application is built to provide for redundancy and availability.
It is also possible to set up storage with replication:
Three times in the region selected.
Three times in two or three data centers within the same region or two different ones.
Hundreds of miles from the primary region in a secondary one (called zone-redundant storage).
The diagram below shows how availability zones allow you to take app design further:
Thanks to the Load Balancer (1) service (the entry point for your application) and with front-end (2) and back-end (3) networks, you can set up a web app (4) with access to a database (5).
Thanks to traffic redirection linked to the load balancer (6 and 7), you can increase your number of servers without impacting your app’s availability.
Finally, you’ll be asked for your instance size, which will also impact the cost. For example, a Windows 2019 Datacenter image has almost 122 different sizes ranging from 1 to 72 CPU and 0.75 to 432 GB of RAM, including variants with top-of-the-range disks able to manage thousands of read/write operations per second.
In the free version, you’ll only have access to a limited number of sizes.
After you set the details of your instance, move into the Administrator Authentication part, where you’ll name your administrator account and generate a password. Then you can move straight onto machine creation and verification, and it will be provisioned in a few minutes.
Your first instance will take longer to create than the next one as you’ll need to create the resource group with the different necessary components for it to operate correctly. These are:
A virtual network.
A network interface.
Storage space for the virtual disk.
A public IP.
A firewall.
You’ll see the option to download a template for automation next to the Create button. It’s an odd name, but it means the option to get the different commands to enter in PowerShell, Azure CLI, or other languages to create the virtual machine you’ve just defined.
Enter the following commands in PowerShell:
<#
.SYNOPSIS
Deploys a template to Azure
.DESCRIPTION
Deploys an Azure Resource Manager template
.PARAMETER subscriptionId
The subscription id where the template will be deployed.
.PARAMETER resourceGroupName
The resource group where the template will be deployed. Can be the name of an existing or a new resource group.
.PARAMETER resourceGroupLocation
Optional, a resource group location. If specified, will try to create a new resource group in this location. If not specified, assumes resource group is existing.
.PARAMETER deploymentName
The deployment name.
.PARAMETER templateFilePath
Optional, path to the template file. Defaults to template.json.
.PARAMETER parametersFilePath
Optional, path to the parameters file. Defaults to parameters.json. If file is not found, will prompt for parameter values based on template.
#>
param(
[Parameter(Mandatory=$True)]
[string]
$subscriptionId,
[Parameter(Mandatory=$True)]
[string]
$resourceGroupName,
[string]
$resourceGroupLocation,
[Parameter(Mandatory=$True)]
[string]
$deploymentName,
[string]
$templateFilePath = "template.json",
[string]
$parametersFilePath = "parameters.json"
)
<#
.SYNOPSIS
Registers RPs
#>
Function RegisterRP {
Param(
[string]$ResourceProviderNamespace
)
Write-Host "Registering resource provider '$ResourceProviderNamespace'";
Register-AzureRmResourceProvider -ProviderNamespace $ResourceProviderNamespace;
}
#******************************************************************************
# Script body
# Execution begins here
#******************************************************************************
$ErrorActionPreference = "Stop"
# sign in
Write-Host "Logging in...";
Login-AzureRmAccount;
# select subscription
Write-Host "Selecting subscription '$subscriptionId'";
Select-AzureRmSubscription -SubscriptionID $subscriptionId;
# Register RPs
$resourceProviders = @("microsoft.network","microsoft.compute","microsoft.storage");
if($resourceProviders.length) {
Write-Host "Registering resource providers"
foreach($resourceProvider in $resourceProviders) {
RegisterRP($resourceProvider);
}
}
#Create or check for existing resource group
$resourceGroup = Get-AzureRmResourceGroup -Name $resourceGroupName -ErrorAction SilentlyContinue
if(!$resourceGroup)
{
Write-Host "Resource group '$resourceGroupName' does not exist. To create a new resource group, please enter a location.";
if(!$resourceGroupLocation) {
$resourceGroupLocation = Read-Host "resourceGroupLocation";
}
Write-Host "Creating resource group '$resourceGroupName' in location '$resourceGroupLocation'";
New-AzureRmResourceGroup -Name $resourceGroupName -Location $resourceGroupLocation
}
else{
Write-Host "Using existing resource group '$resourceGroupName'";
}
# Start the deployment
Write-Host "Starting deployment...";
if(Test-Path $parametersFilePath) {
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath -TemplateParameterFile $parametersFilePath;
} else {
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile $templateFilePath;
}
It’s pretty long, so you need to start by using the portal. But once you’ve got this, you’ll be able to create machines and save yourself a considerable amount of time!
And there you have it! Now all you need to do is identify your needs and create as many machines in as many resource groups as you need.
Let’s Recap!
Azure lets you create services hosted in Microsoft infrastructures in a network of data centers across the globe.
It is possible to manage Azure in three different ways: command line, PowerShell, or the web portal.
There are over 100 services accessible via Azure, from the standard virtual machine to on-demand database services managed by Microsoft.
Azure lets you manage public or private instances accessible by all or networks that you have defined.
Now you know all about Azure, Microsoft’s cloud service.
To get even more familiar with web services, we’ll look at the Windows Server web service, IIS, which can be used – among other things – to host a web app.