Az Lab 08 – Manage Virtual Machines

https://github.com/MicrosoftLearning/AZ-104-MicrosoftAzureAdministrator/blob/master/Instructions/Labs/LAB_08-Manage_Virtual_Machines.md

Task 1: Deploy zone-resilient Azure virtual machines by using the Azure portal and an Azure Resource Manager template
Task 2: Configure Azure virtual machines by using virtual machine extensions
Task 3: Scale compute and storage for Azure virtual machines
Task 4: Register the Microsoft.Insights and Microsoft.AlertsManagement resource providers
Task 5: Deploy zone-resilient Azure virtual machine scale sets by using the Azure portal
Task 6: Configure Azure virtual machine scale sets by using virtual machine extensions
Task 7: Scale compute and storage for Azure virtual machine scale sets (optional)

Task 1: Deploy zone-resilient Azure virtual machines by using the Azure portal and an Azure Resource Manager template

In this task, you will deploy Azure virtual machines into different availability zones by using the Azure portal and an Azure Resource Manager template.

Make az104-08-rg01

Make vm


Click Next: Networking > and, on the Networking tab of the Create a virtual machine blade, click Create new below the Virtual network textbox.

SettingValue
Nameaz104-08-rg01-vnet
Address range10.80.0.0/20
Subnet namesubnet0
Subnet range10.80.0.0/24
SettingValue
Boot diagnosticsEnable with custom storage account
Diagnostics storage accountaccept the default value

Note: If necessary, select an existing storage account in the dropdown list or create a new storage account. Record the name of the storage account. You will use it in the next task.

On the Review + Create blade, click Create.

On the deployment blade, click Template.

Review the template representing the deployment in progress and click Deploy.

Note: You will use this option to deploy the second virtual machine with matching configuration except for the availability zone.

HAHA great, selected a a new location that ms recommended and the policy kicked in:

Lets edit the policy

Add the two locations

It takes 30 min

Lets do WE AND NOT UK SOUTH

make az104-08-rg011, append a 1 for all

Ok, first machine is in progress, now deploy the new from the first

Just add fields

SettingValue
Resource Groupaz104-08-rg01
Network Interface Nameaz104-08-vm1-nic1
Public IP Address Nameaz104-08-vm1-ip
Virtual Machine Name, Virtual Machine Name1, Virtual Machine Computer Nameaz104-08-vm1
Virtual Machine RGaz104-08-rg01
Admin UsernameStudent
Admin PasswordProvide a secure password
Enable Hotpatchingfalse
Zone2

Click Review + Create, on the Review + Create blade, click Create.

Topology

Task 2: Configure Azure virtual machines by using virtual machine extensions

In this task, you will install Windows Server Web Server role on the two Azure virtual machines you deployed in the previous task by using the Custom Script virtual machine extension.

On the st account create a new container and upload the script for install IIS

Script uploaded

Go to the vm and add extensions

On the Install an Extension blade, click Custom Script Extension and then click Next.

From the Configure Custom Script Extension Extension blade, click Browse to st account and select the script

In the Azure portal, search for and select Virtual machines and, on the Virtual machines blade, click az104-08-vm1.

On the az104-08-vm1 blade, in the Automation section, click Export template.

On the az104-08-vm1 – Export template blade, click Deploy.

On the Custom deployment blade, click Edit template.

On the Edit template blade, in the section displaying the content of the template, insert the following code starting with line 20 (directly underneath the “resources”: [ line):

     {
         "type": "Microsoft.Compute/virtualMachines/extensions",
         "name": "az104-08-vm1/customScriptExtension",
         "apiVersion": "2018-06-01",
         "location": "[resourceGroup().location]",
         "dependsOn": [
             "az104-08-vm1"
         ],
         "properties": {
             "publisher": "Microsoft.Compute",
             "type": "CustomScriptExtension",
             "typeHandlerVersion": "1.7",
             "autoUpgradeMinorVersion": true,
             "settings": {
                 "commandToExecute": "powershell.exe Install-WindowsFeature -name Web-Server -IncludeManagementTools && powershell.exe remove-item 'C:\\inetpub\\wwwroot\\iisstart.htm' && powershell.exe Add-Content -Path 'C:\\inetpub\\wwwroot\\iisstart.htm' -Value $('Hello World from ' + $env:computername)"
           }
         }
     },

Note: This section of the template defines the same Azure virtual machine custom script extension that you deployed earlier to the first virtual machine via Azure PowerShell.

Click Save and, back on the Custom template blade, click Review + Create and, on the Review + Create blade, click Create

To verify that the Custom Script extension-based configuration was successful, navigate back on the az104-08-vm1 blade, in the Operations section, click Run command, and, in the list of commands, click RunPowerShellScript.

Invoke-WebRequest -URI http://10.80.0.4 -UseBasicParsing
# You can also connect to az104-08-vm0 and run 
Invoke-WebRequest -URI http://10.80.0.5 -UseBasicParsing 
# to access the web site hosted on az104-08-vm1.

Task 3: Scale compute and storage for Azure virtual machines

In this task you will scale compute for Azure virtual machines by changing their size and scale their storage by attaching and configuring their data disks.

On the az104-08-vm0 virtual machine blade, click Size and set the virtual machine size to Standard DS1_v2 and click Resize


On the az104-08-vm0 virtual machine blade, click Disks, Under Data disks click + Create and attach two disks

save it

On the az104-08-vm0 blade, in the Operations section, click Run command, and, in the list of commands, click RunPowerShellScript.

On the Run Command Script blade, type the following and click Run to create a drive Z: consisting of the two newly attached disks with the simple layout and fixed provisioning:

In the Azure portal, search for and select Virtual machines and, on the Virtual machines blade, click az104-08-vm1.

On the az104-08-vm1 blade, in the Automation section, click Export template.

On the az104-08-vm1 – Export template blade, click Deploy.

On the Custom deployment blade, click Edit template.

On the Edit template blade, in the section displaying the content of the template, replace the line 30 "vmSize": "Standard_D2s_v3" with the following line):

"vmSize": "Standard_DS1_v2"

Note: This section of the template defines the same Azure virtual machine size as the one you specified for the first virtual machine via the Azure portal.

On the Edit template blade, in the section displaying the content of the template, replace line ("dataDisks": [ ] line) with the following code :

"dataDisks": [
                   {
                     "lun": 0,
                     "name": "az104-08-vm1-datadisk0",
                     "diskSizeGB": "1024",
                     "caching": "ReadOnly",
                     "createOption": "Empty"
                   },
                   {
                     "lun": 1,
                     "name": "az104-08-vm1-datadisk1",
                     "diskSizeGB": "1024",
                     "caching": "ReadOnly",
                     "createOption": "Empty"
                   }
                 ]

Note: This section of the template creates two managed disks and attaches them to az104-08-vm1, similarly to the storage configuration of the first virtual machine via the Azure portal.

Click Save and, back on the Custom deployment blade, click Review + Create and, on the Review + Create blade, click Create.

Back on the az104-08-vm1 blade, in the Operations section, click Run command, and, in the list of commands, click RunPowerShellScript.

On the Run Command Script blade, type the following and click Run to create a drive Z: consisting of the two newly attached disks with the simple layout and fixed provisioning:

New-StoragePool -FriendlyName storagepool1 -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks (Get-PhysicalDisk -CanPool $true)

New-VirtualDisk -StoragePoolFriendlyName storagepool1 -FriendlyName virtualdisk1 -Size 2046GB -ResiliencySettingName Simple -ProvisioningType Fixed

Initialize-Disk -VirtualDisk (Get-VirtualDisk -FriendlyName virtualdisk1)

New-Partition -DiskNumber 4 -UseMaximumSize -DriveLetter Z

Task 4: Register the Microsoft.Insights and Microsoft.AlertsManagement resource providers

In the Azure portal, open the Azure Cloud Shell by clicking on the icon in the top right of the Azure Portal.

From the Cloud Shell pane, run the following to register the Microsoft.Insights and Microsoft.AlertsManagement resource providers.

Register-AzResourceProvider -ProviderNamespace Microsoft.Insights

Register-AzResourceProvider -ProviderNamespace Microsoft.AlertsManagement


Task 5: Deploy zone-resilient Azure virtual machine scale sets by using the Azure portal

In this task, you will deploy Azure virtual machine scale set across availability zones by using the Azure portal.

Make az104-08-rg02

In the Azure portal, search for and select Virtual machine scale sets and, on the Virtual machine scale sets blade, click + Add (or + Create).

Choose OS, sku and user etc

On the Networking tab of the Create a virtual machine scale set blade, click the Create virtual network link below the Virtual network textbox and create a new virtual network with the following settings (leave others with their default values):

Back on the Networking tab of the Create a virtual machine scale set blade, click the Edit network interface icon to the right of the network interface entry.

On the Edit network interface blade, in the NIC network security group section, click Advanced and click Create new under the Configure network security group drop-down list.

On the Create network security group blade, specify the following settings (leave others with their default values):

Click Add an inbound rule and add an inbound security rule with the following settings (leave others with their default values):

SettingValue
SourceAny
Source port ranges*
DestinationAny
Destination port ranges80
ProtocolTCP
ActionAllow
Priority1010
Namecustom-allow-http


Click Add and, back on the Create network security group blade, click OK.

Back on the Edit network interface blade, in the Public IP address section, click Enabled and click OK.

Back on the Networking tab of the Create a virtual machine scale set blade, under the Load balancing section, ensure that the Use a load balancer entry is selected and specify the following Load balancing settings (leave others with their default values) and click Next : Scaling >:

On the Scaling tab of the Create a virtual machine scale set blade, specify the following settings (leave others with their default values) and click Next : Management >:

On the Management tab of the Create a virtual machine scale set blade, specify the following settings (leave others with their default values):

az10408diagstaccount

On the Advanced tab of the Create a virtual machine scale set blade, specify the following settings (leave others with their default values) and click Review + create.

Note: The Max spreading setting is currently not functional.

On the Review + create tab of the Create a virtual machine scale set blade, ensure that the validation passed and click Create.

Task 6: Configure Azure virtual machine scale sets by using virtual machine extensions

In this task, you will install Windows Server Web Server role on the instances of the Azure virtual machine scale set you deployed in the previous task by using the Custom Script virtual machine extension.

Add the script to the account


On the az10408vmss0 blade, in the Settings section, click Extensions and applications, and the click + Add.

On the New resource blade, click Custom Script Extension and then click Next.

From the Install extension blade, Browse to and Select the az104-08-install_IIS.ps1 script that was uploaded to the scripts container in the storage account earlier in this task, and then click Create.

In the Settings section of the az10408vmss0 blade, click Instances, select the checkboxes next to the two instances of the virtual machine scale set, click Upgrade, and then, when prompted for confirmation, click Yes.

Done

In the Azure portal, search for and select Load balancers and, in the list of load balancers, click az10408vmss0-lb.

On the az10408vmss0-lb blade, note the value of the Public IP address assigned to the frontend of the load balancer, open an new browser tab, and navigate to that IP address.

Task 7: Scale compute and storage for Azure virtual machine scale sets (optional)

In this task, you will change the size of virtual machine scale set instances, configure their autoscaling settings, and attach disks to them.

Resize the az10408vmss0

Upgrade the scale set instances

In the list of instances, click the entry representing the first instance and, on the scale set instance blade, note its Location (it should be one of the zones in the target Azure region into which you deployed the Azure virtual machine scale set).

Return to the az10408vmss0 – Instances blade, click the entry representing the second instance and, on the scale set instance blade, note its Location (it should be one of the other two zones in the target Azure region into which you deployed the Azure virtual machine scale set).

Return to the az10408vmss0 – Instances blade, and in the Settings section, click Scaling.

On the az10408vmss0 – Scaling blade, select the Custom autoscale option and configure autoscale with the following settings (leave others with their default values):

Click the + Add a rule link and, on the Scale rule blade, specify the following settings (leave others with their default values):

Click Add and, back on the az10408vmss0 – Scaling blade, specify the following settings (leave others with their default values):

In the Azure portal, open the Azure Cloud Shell by clicking on the icon in the top right of the Azure Portal.

If prompted to select either Bash or PowerShell, select PowerShell.

From the Cloud Shell pane, run the following to identify the public IP address of the load balancer in front of the Azure virtual machine scale set az10408vmss0.

$rgName = 'az104-08-rg02'

$lbpipName = 'az10408vmss0-ip'

$pip = (Get-AzPublicIpAddress -ResourceGroupName $rgName -Name $lbpipName).IpAddress

while ($true) { Invoke-WebRequest -Uri "http://$pip" }

Once the third instance is provisioned, navigate to its blade to determine its Location (it should be different than the first two zones you identified earlier in this task.

Zone

On the az10408vmss0 blade, in the Settings section, click Disks, click + Create and attach a new disk, and attach a new managed disk with the following settings (leave others with their default values):

Save the change, in the Settings section of the az10408vmss0 blade, click Instances, select the checkboxes next to the instances of the virtual machine scale set, click Upgrade, and then, when prompted for confirmation, click Yes.

Note: The disk attached in the previous step is a raw disk. Before it can be used, it is necessary to create a partition, create a filesystem, and mount it. To accomplish this, you will use Azure virtual machine Custom Script extension. First, you will need to remove the existing Custom Script Extension

In the Settings section of the az10408vmss0 blade, click Extensions and applications, click CustomScriptExtension, and then click Uninstall.

In the toolbar of the Cloud Shell pane, click the Upload/Download files icon, in the drop-down menu, click Upload and upload the file \Allfiles\Labs\08\az104-08-configure_VMSS_disks.ps1 into the Cloud Shell home directory.

Set-Location -Path $HOME

Get-Content -Path ./az104-08-configure_VMSS_disks.ps1
# Note: The script installs a custom script extension that configures # the attached disk.

From the Cloud Shell pane, run the following to excecute the script and configure disks of Azure virtual machine scale set:

./az104-08-configure_VMSS_disks.ps1

Upgrade the vm instances

Topology for scale set (one subnet not used)