DEV Community

Cover image for 4 Ways to Create Virtual Machine in Microsoft Azure
Kazeem
Kazeem

Posted on

4 Ways to Create Virtual Machine in Microsoft Azure

A virtual machine is an important element of most successful businesses using cloud resources.

Think of a virtual machine as a personal computer with your desired specifications to run different tasks for you. For instance, you need a PC with at least 32GB RAM and over 1TB storage among other specifications. But due to limited financial capabilities, you are unable to purchase the PC. This is one of the ways a virtual machine comes in.

In this article, I will show you five (5) different ways to create virtual machine in Microsoft Azure.

Microsoft Azure is one of the foremost cloud services provider with high credibility. Before you access the Azure portal, you need to sign up for an account - a free tier account is also available with enough resources to get started including a $200 credit.

Now to the real business. How can you create a virtual machine in Microsoft Azure?

Option 1: Using the Azure Portal

Access the Azure Portal by visiting https://portal.azure.com. Input Virtual Machine in the search bar.
Azure Portal Search

In the search results, click "create" on the Virtual Machine icon
Azure Popular Resources

Select your subscription. If you do not have an active subscription, create one or a free trial subscription from Microsoft.

After selecting your subscription, select the resource group this virtual machine should belong to or create a new resource group
Creating Virtual Machine

Give your virtual machine a name - like a computer name. Select an OS (image) for your VM.
Virtual Machine details

After selecting your image and check other information, click on "review + create" to create your virtual machine.
Available image

Deployment will take a moment. After deployment completes, you have successfully created a virtual machine and can go to the resource.
VM Deployed with azure quickstart

Option 2: Using Custom Template from Azure Quickstart

Creating a virtual machine by deploying using a custom template is a fast and easy method that does not require a user to do too much.

Select "Deploy custom template"
Azure Quickstart

On the next page, provide your virtual machine details including an admin username and password.
Azure Virtual Machine Custom Template

Click on "Review + create" and watch the magic!
Create Virtual Machine

Option 3: Using Azure Cloud Shell
Azure Cloud Shell provides us with a simple way to create resource group and virtual machines using simple shell commands.

Open up the cloud shell terminal by clicking on the icon on the azure portal.
Azure Cloud Shell

Select PowerShell in the presented tab.
Cloud Shell

Ensure you are in the right directory. In the image below, we are in the "/home/seidu" directory.
PowerShell Terminal

Before crating a virtual machine, there must be a resource group. The following commands should be run in this form: New-AzResourceGroup -Name "Your Resource Group Name" -Location "Your resource location".
Example:

New-AzResourceGroup -Name "myresourcegroup" -Location "EAST US"
Enter fullscreen mode Exit fullscreen mode

Create resource group

After successfully creating a resource group, we will go ahead to create our virtual machine using this command:
New-AzVM -ResourceGroupName "Resource group name" -Name "vm name" -Location "EAST US"
Example:

New-AzVM -ResourceGroupName "myresourcegroup" -Name MyVm -Location "EAST US"
Enter fullscreen mode Exit fullscreen mode

VM PowerShell command
You will be prompted to provide a username and password for the virtual machine. Virtual machine will then be created and details displayed as in the image below.

VM Created

Option 4: Using Azure Cli
The microsoft azure CLI command is similar to using the power shell commands.

To access the CLI, click on the "BASH" terminal in the cloud shell window.

Azure CLI

To create a resource group, run:
az group create --name "resource group name" --location "Resource Location"
Example:

az group create --name mytestgroup --location EastUS
Enter fullscreen mode Exit fullscreen mode

Resoure Group Azure CLI

To create a virtual machine in our resource group, we run:
az vm create \
--resource-group "resource group name" \
--name "vm machine name" \
--image "os image" \
--generate-ssh-keys

Exmple:

az vm create \
--resource-group myRgGroup \
--name myVmMachine \
--image UbuntuLTS \
--generate-ssh-keys
Enter fullscreen mode Exit fullscreen mode

VM CLI

Conclusion:
Virtual machines are essential for today's businesses as it helps to scale in/out up/down depending on the needs. Microsoft Azure has done so well in this regards by providing developers with all they need.

Important Notice: Remember to delete any resource you create which is not in use in order not to incur unwanted expenses.

Top comments (0)