Introduction

Azure Virtual Machines provide scalable computing resources that you can access on demand. Managing these VMs efficiently is crucial for cost optimization, security, and performance. This tutorial covers essential management tasks, from creation and configuration to monitoring and decommissioning.

Key Management Areas

  • Lifecycle Management: Starting, stopping, restarting, and deleting VMs.
  • Configuration: Disk management, networking, extensions, and custom data.
  • Monitoring & Diagnostics: Using Azure Monitor and boot diagnostics.
  • Scaling: Vertical and horizontal scaling strategies.
  • Security: Network security groups, access control, and patching.
  • Cost Management: Understanding VM costs and optimization techniques.

Prerequisites

  • An Azure subscription.
  • Basic understanding of cloud computing concepts.
  • Azure CLI or Azure PowerShell installed (optional, for command-line management).

Common Management Tasks

1. Starting and Stopping VMs

To save costs, it's often recommended to stop VMs when not in use. You can do this through the Azure portal or Azure CLI.

Azure Portal: Navigate to your VM, then click 'Stop' in the overview pane.

Azure CLI:

az vm deallocate --resource-group  --name 

2. Attaching and Detaching Disks

Manage data disks to add storage capacity or separate OS and data.

Azure Portal: Go to your VM, then 'Disks' > 'Attach existing disks' or 'Create and attach a new disk'.

Azure CLI:

az vm disk attach --vm-name  --resource-group  --name  --new --size-gb 128 --sku Standard_LRS
az vm disk detach --vm-name  --resource-group  --name 

3. Configuring Networking

Adjust network settings, including public IP addresses, network security groups (NSGs), and virtual network configurations.

Azure Portal: Navigate to the VM's 'Networking' section.

Azure CLI:

az network nsg rule create --resource-group  --nsg-name  --name AllowSSH --protocol Tcp --priority 100 --destination-port-range 22 --access Allow
az network public-ip update --resource-group  --name  --allocation-method Static

4. Monitoring VM Performance

Use Azure Monitor to track CPU utilization, disk I/O, network traffic, and set up alerts.

Azure Portal: Select your VM, then 'Insights' or 'Metrics'.

Azure CLI:

az monitor metrics list --resource  --metric CPUUsage --interval PT5M --aggregation Average

5. Applying Updates

Keep your VM's operating system and software up-to-date for security and stability.

Azure Portal: Use VM Image Builder or manually update within the OS.

Azure CLI: For Linux, use package managers like apt or yum. For Windows, consider using Azure Update Management.

6. Deleting VMs

When a VM is no longer needed, decommission it to avoid unnecessary charges.

Azure Portal: Navigate to your VM, then click 'Delete'.

Azure CLI:

az vm delete --resource-group  --name  --yes