Azure CLI 2.0 Cheatsheet
Azure CLI 2.0 cheatsheet for Login, Resources, VMs, Resource groups, Storage, Batch, and Containers.
Logging in
Login with web
Login in CLI
az login -u [email protected]
List accounts
Set subscription
Listing locations and resources / general
List all locations
List all my resource groups
Get what version of the CLI you have
Get help
Creating a basic VM / Resource Group / Storage Account
Get all available VM sizes
Get all available VM images for Windows and Linux
Create a Linux VM
Create a Windows VM
Create a Resource group
Create a Storage account.
az storage account create -g myresourcegroup -n mystorageaccount -l eastus --sku Standard_LRS
DELETING A RESOURCE GROUP
Permanetly deletes a resource group
Managing VM's
List your VMs
Start a VM
Stop a VM
Deallocate a VM
Restart a VM
Redeploy a VM
Delete a VM
Create image of a VM
Create VM from image
List VM extensions
az vm extension list --resource-group azure-playground-resources --vm-name azure-playground-vm
Delete VM extensions
az vm extension delete --resource-group azure-playground-resources --vm-name azure-playground-vm --name bootstrapper
Managing Batch Account
Create a Batch account.
Create a Storage account.
az storage account create -g myresourcegroup -n mystorageaccount -l eastus --sku Standard_LRS
Associate Batch with storage account.
az batch account set -g myresourcegroup -n mybatchaccount --storage-account mystorageaccount
We can now authenticate directly against the account for further CLI interaction.
Display the details of our created account.
Create a new application.
az batch application create --resource-group myresourcegroup --name mybatchaccount --application-id myapp --display-name "My Application"
Add zip files to application
az batch application package create --resource-group myresourcegroup --name mybatchaccount --application-id myapp --package-file my-application-exe.zip --version 1.0
Assign the application package as the default version.
az batch application set --resource-group myresourcegroup --name mybatchaccount --application-id myapp --default-version 1.0
Retrieve a list of available images and node agent SKUs.
Create new Linux pool with VM config
az batch pool create \
--id mypool-linux \
--vm-size Standard_A1 \
--image canonical:ubuntuserver:16.04.0-LTS \
--node-agent-sku-id “batch.node.ubuntu 16.04”
Now let's resize the pool to start up some VMs.
We can check the status of the pool to see when it has finished resizing.
List the compute nodes running in a pool.
If a particular node in the pool is having issues, it can be rebooted or reimaged.
A typical node ID will be in the format 'tvm-xxxxxxxxxx_1-
Re-allocate work to another node.
az batch node delete \
--pool-id mypool-linux \
--node-list tvm-123_1-20170316t000000z tvm-123_2-20170316t000000z \
--node-deallocation-option requeue
Create a new job to encapsulate the tasks that we want to add.
Add tasks to the job.
…where
az batch task create --job-id myjob --task-id task1 --application-package-references myapp#1.0 --command-line "/bin/<shell> -c /path/to/script.sh"
Add many tasks at once
Now that all the tasks are added - we can update the job so that it will automatically be marked as completed once all the tasks are finished.
Monitor the status of the job.
Monitor the status of a task.
Delete a job
Managing Containers
If you HAVE AN SSH run this to create an Azure Container Service Cluster (~10 mins)
If you DO NOT HAVE AN SSH run this to create an Azure Container Service Cluster (~10 mins)