Create virtual machines with the Azure PowerShell
Today in this article, we will see how to create virtual machines with the Azure PowerShell step by step. we will also cover a few best practices on managing the scripts and resources etc.
We will cover the below aspects with this step by step article,
- Create Azure account
- Launch Azure cloud shell i.e powershell
- Create Resource group
- Create Virtual machine
- Connect to VM
- Deploy WebServer in VM
- Test you WebApp deployed in VM
- How to clean the resources
Getting started
Create Azure account
Before you could begin, please make sure you have an Azure cloud Active subscription.
Please visit: Create Azure account
Launch Azure cloud shell i.e powershell
Azure PowerShell is a useful utility designed for managing and administering Azure resources effectively from the CLI commands line. Use Azure PowerShell to automate anything in the Azure environment.
Alternatively, cloud shell can be launched using below,
https://shell.azure.com/powershell
CloudShell – Create Resource group
A resource group is a logical container holding your Azure resources that are deployed and managed.
Create an Azure resource group with New-AzResourceGroup.
Command
New-AzResourceGroup -Name TheCodeBuzz -Location 'EastUS'
Example
CloudShell – Create Virtual Machine
Azure cloud shell provides a command called New-AzVM which helps you create the VM based on the inputs specified in the commands.
Step1-
Before creating VM, please create a credentials object containing a username and password for the administrator account of the Windows VM.
Command
New-AzVm
-ResourceGroupName 'thecodebuzz'
-Name 'devvm'
-Location 'Specifiy locaiton Ex. East US'
-VirtualNetworkName 'Vnet'
-SubnetName 'Subnet'
-SecurityGroupName 'specify security group name'
-PublicIpAddressName 'specify IP address'
-OpenPorts 80,3389
Connect to VM
Let’s now Connect via SSH with the client
Open Cloudshell CLI command line lets upload the downloaded private key(This key was downloaded as part of VM creation)
Please run the below set of commands to connect.
ls chmod 400 azureuser.pem ssh -i vmfirst_key.pem azureuser@20.127.10.153
Deploy WebServer in VM
Let’s install NGNIX Webserver as the next step,
sudo apt-get -y update
sudo apt-get -y install nginx root@devvm:/home/thecodebuzz# echo "Hello TheCodeBuzz"> /var/www/html/index.html
Let’s verify installed Web application by hitting the IP,
References:
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.