0
0
Azurecloud~5 mins

Why VMs provide compute flexibility in Azure - Why It Works

Choose your learning style9 modes available
Introduction
Virtual Machines (VMs) let you run many different software programs on one physical computer. They give you the power to change how much computing power you use, so you only pay for what you need.
When you want to run multiple different applications on one physical server without them interfering with each other
When you need to quickly add more computing power to handle more users or data
When you want to test new software safely without affecting your main system
When you want to move your applications easily between different physical servers
When you want to save money by using only the computing resources you need at any time
Commands
This command creates a new virtual machine in Azure with a small size to start. It sets up a user and SSH keys for secure access.
Terminal
az vm create --resource-group example-group --name example-vm --image UbuntuLTS --size Standard_B1s --admin-username azureuser --generate-ssh-keys
Expected OutputExpected
{ "fqdns": "", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/example-group/providers/Microsoft.Compute/virtualMachines/example-vm", "location": "eastus", "name": "example-vm", "powerState": "VM running", "resourceGroup": "example-group", "zones": "" }
--size - Sets the VM size which controls compute power
--image - Chooses the operating system for the VM
--generate-ssh-keys - Creates SSH keys for secure login
This command changes the VM to a bigger size with more CPU and memory to handle more work.
Terminal
az vm resize --resource-group example-group --name example-vm --size Standard_B2s
Expected OutputExpected
Succeeded
--size - Specifies the new VM size to increase compute resources
This command checks the current size of the VM to confirm the resize worked.
Terminal
az vm show --resource-group example-group --name example-vm --query "hardwareProfile.vmSize" -o tsv
Expected OutputExpected
Standard_B2s
Key Concept

If you remember nothing else from this pattern, remember: VMs let you quickly change computing power by resizing, giving you flexible control over resources.

Common Mistakes
Trying to resize a VM while it is running without stopping it first
Some VM sizes require the VM to be stopped before resizing, so the command will fail or cause errors
Stop the VM using 'az vm deallocate' before resizing, then start it again after resizing
Choosing a VM size that does not exist in the selected region
Azure does not offer all VM sizes in every region, so the creation or resize will fail
Check available VM sizes in the region with 'az vm list-sizes --location eastus' before creating or resizing
Summary
Create a VM with a chosen size to start with the right amount of compute power.
Resize the VM to increase or decrease compute resources as your needs change.
Verify the VM size after resizing to ensure the change was successful.