Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Azure Compute: Virtual Machines (VMs)

Introduction

Virtual Machines (VMs) in Azure allow you to deploy and manage scalable computing resources. A VM is an emulation of a computer system that provides the same functionality as a physical computer. Virtual Machines are one of the foundational services provided by Azure, enabling users to run applications, store data, and perform various computing tasks in the cloud.

Creating a Virtual Machine

To create a Virtual Machine in Azure, you can use the Azure Portal, Azure CLI, or PowerShell. Below are the steps to create a VM using the Azure Portal:

  1. Log in to the Azure Portal.
  2. Navigate to "Virtual Machines" and click on "Add".
  3. Fill in the necessary details such as Subscription, Resource Group, and VM Name.
  4. Choose an image for the VM (e.g., Windows Server, Ubuntu).
  5. Select the VM size based on your requirements.
  6. Configure any additional settings such as networking, management, and monitoring.
  7. Review and create the VM.

Using Azure CLI to Create a VM

You can also create a Virtual Machine using the Azure CLI. Below is an example:

az vm create \

--resource-group myResourceGroup \

--name myVM \

--image UbuntuLTS \

--admin-username azureuser \

--generate-ssh-keys

After running the above command, Azure will create a Virtual Machine with the specified configuration. The SSH keys will be generated and stored in your local machine for secure access.

Managing Virtual Machines

Once your VM is up and running, you can manage it using the Azure Portal, Azure CLI, or PowerShell. Common management tasks include:

  • Starting or stopping the VM
  • Restarting the VM
  • Resizing the VM
  • Attaching or detaching disks
  • Configuring networking settings

Here is an example of stopping a VM using the Azure CLI:

az vm stop \

--resource-group myResourceGroup \

--name myVM

Connecting to a Virtual Machine

To connect to your Azure VM, you can use SSH for Linux VMs or Remote Desktop Protocol (RDP) for Windows VMs.

Connecting to a Linux VM

Use the SSH command to connect to your Linux VM:

ssh azureuser@

Connecting to a Windows VM

Use Remote Desktop Connection (RDP) to connect to your Windows VM. Open the RDP client and enter the IP address of your VM, then provide the login credentials.

Monitoring and Scaling Virtual Machines

Azure provides various tools to monitor and scale your VMs:

Monitoring

Use Azure Monitor to track the performance and health of your VMs. You can set up alerts and view metrics such as CPU usage, memory usage, and network traffic.

Scaling

Azure enables you to scale your VMs up or down based on your needs. You can manually resize your VMs or set up auto-scaling rules to automatically adjust the number of VM instances in your deployment.

Conclusion

Virtual Machines in Azure provide a flexible and scalable way to run your applications in the cloud. By understanding how to create, manage, and monitor VMs, you can leverage Azure's powerful computing capabilities to meet your business needs.