Deploying Your First Azure Virtual Machine

A comprehensive guide to setting up a VM in Azure.

Introduction

This tutorial will walk you through the essential steps to create and configure your very first Virtual Machine (VM) on Microsoft Azure. Azure VMs provide on-demand, scalable computing resources, allowing you to deploy and manage applications without the need for physical hardware.

Note: This tutorial assumes you have an active Azure subscription. If not, you can create a free account.

Prerequisites

  • An Azure Subscription (Free trial or Paid).
  • A web browser with internet access.

Step 1: Sign in to the Azure Portal

Navigate to the Azure Portal

Open your web browser and go to https://portal.azure.com. Sign in using your Azure account credentials.

Locate the Virtual Machines Service

Once logged in, you will see the Azure dashboard. In the search bar at the top, type "Virtual machines" and select "Virtual machines" from the results.

Placeholder for "Virtual Machines" search result

Step 2: Create a New Virtual Machine

Start the Creation Process

On the Virtual machines page, click the + Create button and then select Virtual machine.

Placeholder for "+ Create" button

Configure Basic Settings

You will be presented with several tabs to configure your VM. Let's start with the 'Basics' tab:

  • Subscription: Select your Azure subscription.
  • Resource group: Click "Create new" and give it a descriptive name (e.g., myResourceGroup-VM). A resource group is a logical container for your Azure resources.
  • Virtual machine name: Enter a unique name for your VM (e.g., myFirstVM).
  • Region: Choose a region geographically close to you or your users.
  • Availability options: For this tutorial, you can leave this as default ("No infrastructure redundancy required").
  • Security type: Leave as "Standard".
  • Image: Select an operating system image. For example, choose Windows Server 2022 Datacenter: Azure Edition - Gen2 or a Linux distribution like Ubuntu Server 22.04 LTS - Gen2.
  • Size: Choose a VM size that fits your needs and budget. For testing, a smaller size like Standard_B1s or Standard_D2s_v3 is often sufficient.
  • Administrator account:
    • Username: Enter an administrator username (e.g., azureuser).
    • Password: Enter a strong password, confirm it. Alternatively, you can use SSH public key authentication for Linux VMs.
  • Inbound port rules:
    • Public inbound ports: Select Allow selected ports.
    • Select inbound ports: For Windows, select RDP (3389). For Linux, select SSH (22). This allows you to connect to your VM.
Placeholder for 'Basics' tab

Configure Disks

On the 'Disks' tab, you can configure the storage for your VM. The default settings are usually fine for a basic setup. You can choose the OS disk type (e.g., Premium SSD for better performance).

Placeholder for 'Disks' tab

Configure Networking

On the 'Networking' tab, Azure automatically creates a virtual network, subnet, public IP address, and network security group (NSG). You can review these or customize them if you have specific requirements. Ensure the NSG allows inbound traffic on the port you selected (RDP or SSH).

Placeholder for 'Networking' tab

Advanced and Tags (Optional)

The 'Advanced' tab allows for further customization like extensions, cloud-init data (for Linux), and management settings. The 'Tags' tab is useful for organizing your Azure resources. You can add tags like Environment: Development or Project: MyProject.

Review and Create

Click the Review + create button. Azure will validate your configuration. If validation passes, you'll see a summary of your VM settings. Review everything carefully, then click Create.

Placeholder for 'Review + create' validation

Important: If you are using SSH keys for Linux and chose that option, you will be prompted to download your private key. Store this key securely, as it's your only way to access the VM.

Deployment Progress

Azure will now start deploying your virtual machine. This process typically takes a few minutes. You can monitor the deployment progress on the deployment page.

Placeholder for deployment progress

Step 3: Connect to Your Virtual Machine

Accessing the VM Overview

Once the deployment is complete, click on "Go to resource" or navigate back to the "Virtual machines" service and select your newly created VM. You will see the VM's overview page.

For Windows VM (RDP)

  1. On the VM overview page, click the Connect button.
  2. Select "RDP" and click "Download RDP File".
  3. Open the downloaded RDP file.
  4. When prompted, click "Connect".
  5. Enter the username and password you created earlier.
  6. You may see a certificate warning; click "Yes" to proceed.
Placeholder for RDP connection

For Linux VM (SSH)

  1. On the VM overview page, click the Connect button.
  2. Select "SSH". You will see connection instructions.
  3. Open your terminal or SSH client.
  4. Use the provided command, replacing placeholders with your VM's public IP address and your username. If using an SSH key, ensure the key file has the correct permissions (chmod 400 /path/to/your/private.key).
  5. Example command: ssh azureuser@20.45.67.89 (replace with your details).
  6. If prompted about the authenticity of the host, type yes.
Placeholder for SSH connection

You can find your VM's Public IP address on the VM overview page.

Step 4: Basic VM Management

Starting and Stopping Your VM

On the VM overview page, you can use the Start, Stop, and Restart buttons to manage the VM's power state. Stopping a VM deallocates its resources, saving costs.

Placeholder for Start/Stop buttons

Monitoring Performance

The "Monitoring" section of the VM blade provides insights into CPU usage, network traffic, disk I/O, and more. This is crucial for understanding your VM's performance and identifying potential issues.

Deleting Your VM

When you no longer need the VM, it's important to delete it to avoid ongoing charges. Navigate to the VM's overview page, click Delete. You will typically also want to delete the associated resources like the Public IP address, Network Interface, and Disks if they are no longer needed. Deleting the resource group will also delete all resources within it.

Caution: Deleting a VM and its associated resources is irreversible. Ensure you have backed up any critical data before proceeding.

Conclusion

Congratulations! You have successfully deployed and connected to your first Azure Virtual Machine. This is a fundamental building block for many cloud solutions. You can now install applications, host websites, or run any workload you need.

Explore further by learning about different VM sizes, storage options, networking configurations, and security best practices in Azure.