Lab: Deploying Azure Virtual Machines and Networking
Describe Azure compute and networking services
Lab: Deploying Azure Virtual Machines and Networking
This hands-on lab introduces the foundational compute and networking services of Microsoft Azure. You will create a Resource Group, configure a Virtual Network (VNET), and deploy a Linux Virtual Machine. This corresponds to the AZ-900 Unit 2 learning outcomes.
[!WARNING] Remember to run the teardown commands at the end of this lab to avoid ongoing charges to your Azure account.
Prerequisites
- Azure Subscription: An active Azure account (Free Trial or Pay-As-You-Go).
- Interface:
- Azure Cloud Shell (recommended for CLI) or local installation of Azure CLI.
- Azure Portal access via web browser.
- Estimated Time: 15 minutes.
Learning Objectives
- Create and manage an Azure Resource Group to organize cloud assets.
- Configure an Azure Virtual Network (VNET) and Subnet.
- Deploy an Azure Virtual Machine using the CLI and explore Portal alternatives.
- Verify connectivity and resource deployment.
Architecture Overview
The following diagram illustrates the relationship between the resources you will deploy. Note that the Virtual Machine must reside within a Subnet, which resides within a VNET, all contained within a Resource Group.
Network Address Space Visual
Step-by-Step Instructions
Step 1: Create a Resource Group
Azure resources must be placed in a Resource Group. This serves as a logical container for your lab assets.
az group create --name brainybee-lab-rg --location eastus▶Console alternative
- Search for
in the top search bar. 2. Click
. 3. Select your subscription, name it
brainybee-lab-rg, and choose
as the region. 4. Click
, then
.
[!TIP] Choose a region close to your physical location for better latency, though
eastusis generally reliable for labs.
Step 2: Create a Virtual Network and Subnet
Networking is the backbone of Azure compute. You must define the address space before deploying a VM.
az network vnet create \
--resource-group brainybee-lab-rg \
--name brainybee-lab-vnet \
--address-prefix 10.0.0.0/16 \
--subnet-name default \
--subnet-prefix 10.0.1.0/24▶Console alternative
- Search for
. 2. Click
. 3. Select
brainybee-lab-rg. 4. Name it
brainybee-lab-vnet. 5. On the
tab, ensure the IPv4 address space is
10.0.0.0/16. 6. Add a subnet named
defaultwith the range
10.0.1.0/24. 7. Click
.
Step 3: Create the Virtual Machine
Now we deploy a compute resource (Linux VM) into the networking infrastructure we just built.
az vm create \
--resource-group brainybee-lab-rg \
--name brainybee-lab-vm \
--image Ubuntu2204 \
--admin-username azureuser \
--generate-ssh-keys \
--vnet-name brainybee-lab-vnet \
--subnet default[!IMPORTANT] The
--generate-ssh-keysparameter creates security keys for you if they don't exist. Keep track of where they are saved (usually~/.ssh).
▶Console alternative
- Search for
. 2. Click
. 3. Basic Tab: Name:
brainybee-lab-vm, Image:
, Size:
(cheapest). 4. Networking Tab: Ensure
brainybee-lab-vnetand
defaultsubnet are selected. 5. Click
.
Checkpoints
After running the commands above, verify the deployment:
- CLI Verification: Run the following to see your VM's public IP address.
bash
az vm list-ip-addresses --resource-group brainybee-lab-rg --name brainybee-lab-vm --output table - Portal Verification: Navigate to the Azure Portal, open Resource Groups, select
brainybee-lab-rg. You should see four resources: Virtual Machine, Network Interface, Public IP, and Virtual Network. - Status Check: Ensure the "Provisioning State" of the VM is Succeeded.
Troubleshooting
| Error / Issue | Likely Cause | Fix |
|---|---|---|
Ssh key file... not found | Local environment lacks SSH keys | Use --generate-ssh-keys or create keys manually with ssh-keygen. |
LocationNotAvailable | Regional capacity limits | Try changing the location to westus2 or northeurope. |
ResourceGroupNotFound | Typo in name or Step 1 failed | Re-run the az group create command and verify with az group list. |
Clean-Up / Teardown
To avoid any costs, delete the entire Resource Group. This will automatically delete the VM, VNET, and all associated disks.
az group delete --name brainybee-lab-rg --no-wait --yes[!NOTE] The
--no-waitflag allows the command to return immediately while Azure processes the deletion in the background.
Concept Review
| Service | Type | Primary Purpose |
|---|---|---|
| Resource Group | Management | Logical grouping of related resources. |
| Virtual Network | Networking | Isolated environment for resources to communicate. |
| Subnet | Networking | A range of IP addresses in the VNET to segment traffic. |
| Virtual Machine | Compute | On-demand, scalable computing resources (IaaS). |