Azure Course Labs

Virtual Machines

Virtual Machines in the cloud are pretty much the same as VMs in the datacenter or on your desktop. They’re an isolated compute environment running with a full operating system, where you have admin permissions to install and configure whatever you need. Azure can run Linux and Windows VMs, with a large choice of preconfigured images and compute sizes.

Reference

Explore VMs in the Portal

Open the Portal and search to create a new Virtual Machine resource. There are lots of configuration options but the main ones are:

The basic options cover the OS type, CPU, memory and connectivity. Look at the required options - what other resources do you need to create before you get to the VM?

All resources belong inside a resource group; you can typically create dependent resources directly in the portal.

Check the Disks and Networking tabs and you’ll see how you can configure VMs with the exact setup you need:

We won’t go on to create the VM in the portal, we’ll use the CLI instead.

Create a Linux VM with the CLI

First we need to create a Resource Group where the new VM resources will live. This should be familiar from the Resource Groups lab:

Create the group - use your own preferred location:

az group create -n labs-vm --tags courselabs=azure -l westeurope

Find a valid (small) VM size for your subscription & region:

# with PowerShell:
az vm list-sizes -o table --query "[?numberOfCores<=``2`` && memoryInMb==``2048``]" --location "westeurope"

# or Bash:
az vm list-sizes -o table --query "[?numberOfCores<=\`2\` && memoryInMb==\`2048\`]" --location "westeurope"

JMESPath takes some getting used to. How are we filtering the list of VMs?

The VM sizes available will depend on your subscription, the region you choose and the spare capacity in that region. The Azure free trial subscriptions might have restrictions which paid subscriptions don’t.

Now you can create a small VM which will be cheap to run.

📋 Create an Ubuntu Server VM using a vm create command. There are a few parameters you’ll need to specify.

Not sure how?  

Print the help text:

az vm create --help

As a minimum you need to specify:

This will get you started:

# it's good to include a size, as the default might not be available
az vm create -l westeurope -g labs-vm -n vm01 --image UbuntuLTS --size Standard_A1_v2


Creating a new VM takes a few minutes. While it’s running, check the docs to answer this:

When your VM is created, browse to the portal and open the Resource Group. You’ll see the VM together with all the supporting resources.

Connect to the VM

This is a Linux VM, so you can use SSH to connect - the SSH command line is installed by default on MacOS, Linux and the latest Windows machines.

📋 Find the IP address of your server and connect with ssh.

Not sure how?

The key details of the VM are printed when the vm create command completes. You can print them again with the vm show command:

az vm show --help

You’ll see there’s a parameter to set if you want to include the IP address in the response:

az vm show -g labs-vm -n vm01 --show-details

The field you want is publicIps. You can add a query to return just that field and store the IP address in a variable:

# using PowerShell:
$pip=$(az vm show -g labs-vm -n vm01 --show-details --query "publicIps" -o tsv)

# or a Linux shell:
pip=$(az vm show -g labs-vm -n vm01 --show-details --query "publicIps" -o tsv)

(Or you can find the public IP address from the Portal).

Now you can connect:

ssh $pip


You should be able to connect without specifying a username or password.

This is a standard Ubuntu Server VM. You can run typical commands like:

Lab

Use the CLI to print the details of the VM’s disk. What is the disk performance in read/write IOPS? Then delete the VM - does the disk get deleted too?

Stuck? Try hints or check the solution.


Cleanup

Delete the RG with this command and that will remove all the resources:

az group delete -y -n labs-vm