In this hands-on lab, we play the part of a Cloud Engineer who is tasked with using the Azure CLI to provision a Linux-based virtual machine running Nginx. This VM is intended for our web development team’s newest project. In this hands-on lab, we cover Azure CLI syntax, Azure CLI help/parameters, and Network Security Groups.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create a Virtual Machine
Create a Virtual Machine Using Azure CLI and the Following Settings:
- Resource Group: (Existing resource group)
- Name: LabVM
- Image: UbuntuLTS
- Admin Username: azureuser
- Authentication Method: Generate SSH Keys
Note: The resource group has already been created for you.
- Login to the Azure Portal using the credentials provided in this hands-on lab.
- Navigate to the Cloud Shell, using the
>_
icon in the toolbar on the top-right side of the screen. - Ensure you are using PowerShell for Azure Cloud Shell.
- Click
Show advanced settings
. - Use the existing Resource Group.
- Choose the
Cloud Shell Region
that matches the location of your lab provided Resource Group. - Under the
Storage account
section selectUse existing
. - Under the
File share
section selectCreate new
and type incloudshell
. - Select
Attach storage
. - Once Cloud Shell has opened, identify the existing Resource Group using
az group list
. - Copy the value of the
name:
field. This is the Resource Group name. - Set the Resource Group variable by typing
$rg = "<insert-resource-group-name>"
and pressEnter
. - Set the virtual machine’s name by creating its variable with
$vm = "kaldiVM"
. - Deploy a virtual machine (VM) by typing:
az vm create -g $rg -n $vm --image "UbuntuLTS" --admin-username "azureuser" --generate-ssh-keys
- After the VM is created copy the
publicIPAddress
for later use.
- Open Port 80 On the VM for Web Traffic
Open Port 80 on VM using Azure CLI
- Open port 80 on the VM we created:
az vm open-port -g $rg -n $vm --port 80
- Install Nginx by first logging into the server. Don’t forget to accept the fingerprint:
ssh azureuser@<PubliIP.OF.VM>
- Update the Ubuntu VM:
sudo apt update -y
- Install Ngnix:
sudo apt-get install nginx -y
- Navigate to the web browser and paste in the VM’s IP address. If successful, the default "Welcome to Nginix!" page appears.
- Install Nginx by first logging into the server. Don’t forget to accept the fingerprint:
- Open port 80 on the VM we created: