Azure CLI With Demo Creating VM Using Azure CLI

Azure command line interface (CLI) is written in node.js while Azure PowerShell is written in C#. Using Azure CLI, you can deploy your templates to Azure.

Like Azure PowerShell, it also follows imperative script executions and supports all - Mac, Windows, and Linux. However, performance-wise, it is a bit slower in execution in comparison to the Azure PowerShell.
 
Step 1 - Download and install Azure CLI
  •  You can download Azure CLI from the link given here: Download Azure Resources 
  •  From the above-mentioned link, you can simply download and install Azure CLI Installer.
  • If you have already installed Azure CLI, then you can run MSI again to update it to the latest version.
 Step 2 - Open your command prompt and load Azure CLI 
  • Once Azure CLI is installed, open your command prompt and fire the command az.
  • It will load the Azure CLI environmeat in your command prompt.

      
Step 3 - Authenticate your Azure CLI session 

command - az login 
  • The az login command will ask us to navigate to the given URL and provide the authentication code for the device.
  • Once verified, it will allow your device for paritcular session of Azure CLI.



     
Once you provide the code, it will ask you to provide Azure subscription credentials and finally, you will get a success message, as shown below.

 

Also, if you go to command prompt, it will show you your available Azure subscription/s.

 
 
Step 4 - Select your account/subscription of choice to conitnue session with

command.- az acoount set 

       
Step 5 - Create a Resource Gorup before you begin with.

command :- az group create. We will pass value for two parameters here, Resource Group name and location of Azure datacenter.
 
 
Step 6 - Create a stroage account to put your vhds and other resources.

az storage account create
 
For this storage account, we will set the storage type local redundant and disks would be unmanaged disks.

 

Step 7 -
Define VNET and SubNet configurations.

az network vnet create
 
This command allows you to define you Virtual Network and Subnet.

Example
  • az network vnet create --resource-group KrunalCLIRG --location centralus --name KrunalCLIVnet --address-prefix 10.10.0.0/16 --subnet-name KrunalCLISubnet --subnet-prefix 10.10.0.0/24
         

Step 8 - Public ip configuration

az network public-ip create
 
This command will define the public IP endpoint for your Azure Virtual Machine.

example 
  • az network public-ip create --resource-group KrunalCLIRG --location centralus --name KrunalCLIPublicIP --dns-name krunalclipublicdns --allocation-method static --idle-timeout 5
          

Step 9 - Network Security Group creation,

az network nsg create

Using this command, we will define Network Security Group and then, we will define the Network Interface Card. 

example 
  • az network nsg create --resource-group KrunalCLIRG --location centralus --name CLINSG

Step 10 -  Define Networwk Interface Card within NSG created in the previous step.

az network nic create.
 
This command allows the creation of NIC and links it to the subnet , VNET, and NSG.

example
  • az network nic create --resource-group KrunalCLIRG --location centralus --name CLINic1 --vnet-name KrunalCLIVnet --subnet KrunalCLISubnet --network-security-group CLINSG

Step 11 - Create your Virtual Machine. 

command

az vm create. This command provisions an actual virtual machine with the image specified in the command.

Example 
  • az vm create --resource-group KrunalCLIRG --name KrunalCLIVM1 --location centralus --nics CLINic1 --image UbuntuLTS --generate-ssh-keys --admin-username krunaltrivedi

Now go to ARM portal and you can check all the resources are provisioned under your resource group you have created first.

 


Similar Articles