Implement Solutions that Use Virtual Machines Flashcards
Virtual Machine Components
- Resource Group
- VM Size
- Network
- Images
- Virtual Disk/Storage
Azure Virtual Machine Main Creation Methods
Azure Portal Azure CLI Azure PowerShell with AZ module Azure ARM templates (APIs also exist)
Basic Details needed to Create a Virtual Machine (in the Azure Portal)
Basic: Subscription Resource Group Details: VM Name Region Image - list available in your selected region (not required) Azure Spot Instance VM Size - list available in your selected region Administrative: Administrator Account Username* Administrator Account Password* *Linux Can Use Username/ Password OR SSH public key Inbound port rules: Public Inbound Ports Select Inbound ports - permits inbound access from any machine on the specified port.
Azure Spot Instance
Setting that allows Azrue to stop and deallocate a virtual machine if Azure needs compute capacity back for whatever reason.
Linux alternative to VM Admin Username Password
SSH Public Key
Public Inbound Ports - Azure Portal
Setting when creating Azure VM instance in the inbound port rules section
Default access outside the Virtual Network or the internet is not permitted
Selecting an inbound port creates a rule to allow ANY machine to access the selected port(s)
More granular rules available in ‘networking’ (specify IPs etc)
Availability Options for Azure VM
No Infrastructure redundancy required,
Availability Zone
Availability Set
Reasons to Deploy VMs with code in Azure
- Add consistency to your deployments and VM creation
- Any production system should be implemented using automation
- Construct similar down-level environments such as DEV/TEST
Tools for Programmatic VM Creation
Azure CLI
Azure PowerShell
ARM Templates
Steps to create VM programmatically
- Create Resource Group (or choose existing resource group)
- Execute command to create Virtual Machine w/parameters
- Ensure Networking is correct - Remote Access Port may need to be Open, application ports may need to be open, etc.
-can also add rules to the network security group directly to control access to this VM based on ports & IP addresses
(recommended) - Retrieve Public IP address to connect
Azure CLI Create Resource Group Command
az group create –name “resource group name” \
–location ‘“location”
Create VM Azure CLI command
az vm create
–resource-group “resource-group-name” \
–name “name” \
–image “image -name” \
~admin option choice~
–size “size - default = standard ds1 v2”)
Admin options 1:
- -admin-username “username” \
- -admin-password “password
Admin options 2:
- -admin-username “username” \
- -authentication-type “ssh” \
- -ssh-key-value “path-to-key-value”
Default VM Size if Not specified
Standard Ds1 v2
Enable Remote Access w/ Azure CLI
az vm open-port
- -resource-group “rg-name” \
- -name “vm-name” \
- -port “port to open number”
Get VM public address via Azure CLI
az vm list-ip-addresses \
- -resource-group “resource group name” \
- -name “vm name” \
- -output table
What type of Object must be created in Azure Powershell to hold username/password for a local admin on a VM?
PSCredential
example script:
$username =’username’
$password = ConvertTo-SecureString ‘somepassword’ -AsPlainText -Force
$WindowsCred = New-Object System.Management.Automation.PSCredential ($username, $password)
Create New VM in Azure PowerShell Command
New-AzVM
- ResourceGroupName $resource GroupName
- Name $VM Name
- Image $imageName
- Credential $WindowsCred
- OpenPorts 99999
(Minimum info needed)
Which of these methods of VM creation can specify open ports at VM Creation?
Azure CLI
Azure PowerShell
Azure PowerShell
Using the -OpenPorts parameter of New-AzVm command
Get Azure VM Public IP address via PowerShell Command
Get-AzPublicIpAddress
- ResourceGroupName ‘rg-name’
- Name ‘vm-name’
Can add pipe to the end to get only ipaddress property :
… | Select-Object IpAddress
PowerShell Command to Log In to Azure
Connect-AzAccount -SubscriptionName ‘your sub name’
PowerShell Command to point to correct subscription
Set-AzContext -SubscriptionName ‘sub-name’
Azure Powershell Create Resource Group Command
New-AzResourceGroup
- Name ‘rg-name’
- Location ‘location’