AzureCookBook - henk52/knowledgesharing GitHub Wiki
Azure cook book
Introduction
Purpose
References
Vocabulary
- Service principals - Service account
First use of Azure
- Set two-factor for the azure login
- Set two-factor for the mail service access for the account used for azure
Sign up for Azure
Create the first resources
access azure with az
Install the azure cli az
Installing az on Ubuntu
- sudo apt-get update
- sudo apt-get install ca-certificates curl apt-transport-https lsb-release gnupg
- sudo mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | sudo tee /etc/apt/keyrings/microsoft.gpg
- sudo chmod go+r /etc/apt/keyrings/microsoft.gpg
- AZ_REPO=$(lsb_release -cs)
- echo "deb [arch=
dpkg --print-architecture
signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo tee /etc/apt/sources.list.d/azure-cli.list - sudo apt-get update
- sudo apt-get install azure-cli
Installing az on Windows 10
See: Choose the second method, so that it becomes part of the repos and are auto updated with apt update/upgrade
- Download installer from:
- run the azure-cli-*.msi installer
- Accept license terms and click 'Install'
- click 'Yes' to allow app to make changes to system.
- click 'Finished' when done
- The installation take 5-8 minutes?
az commands
VM
Access VM
- Set the NSG so only your ip is allowed to access the VM.
- mv ~/Downloads/ubuntu1_key.pem ~/.ssh
- chmod 600 ~/.ssh/ubuntu1_key.pem
- ssh -i ~/.ssh/ubuntu1_key.pem azureuser@PUBLIC_IP
VM creation
Create VM and network in one script
#!/bin/bash
PARM_CONF_DIR="${HOME}/my_azure_config"
RESOURCE_GROUP_NAME=$(cat ${PARM_CONF_DIR}/azure_resource_group_name)
NSG_NAME="tst-k8s-nsg"
VNET_NAME="tst-k8s-vnet"
SUBNET_NAME="K8sSubnet"
echo "III Create NSG - ${NSG_NAME}"
# https://docs.microsoft.com/en-us/cli/azure/network/nsg?view=azure-cli-latest
az network nsg create \
--name ${NSG_NAME} \
--resource-group ${RESOURCE_GROUP_NAME}
echo "III create rule - ssh"
az network nsg rule create \
--name ssh \
--nsg-name ${NSG_NAME} \
--resource-group ${RESOURCE_GROUP_NAME} \
--priority 303 \
--access Allow \
--destination-port-ranges 22 \
--direction Inbound \
--protocol Tcp \
--source-address-prefixes 140.101.0.0/16
echo "III create vnet - ${VNET_NAME}/${SUBNET_NAME}"
# https://docs.microsoft.com/en-us/cli/azure/network/vnet?view=azure-cli-latest
az network vnet create \
--name ${VNET_NAME} \
--resource-group ${RESOURCE_GROUP_NAME} \
--address-prefixes 10.0.0.0/16 \
--network-security-group ${NSG_NAME} \
--subnet-name ${SUBNET_NAME} \
--subnet-prefixes 10.0.0.0/24
echo "III create VM - tst_k8s_minikube"
az vm create \
--resource-group ${RESOURCE_GROUP_NAME} \
--name tst_k8s_minikube \
--size Standard_B2s \
--vnet-name ${VNET_NAME}\
--subnet ${SUBNET_NAME} \
--public-ip-sku Standard \
--image Canonical:0001-com-ubuntu-server-focal:20_04-lts:20.04.202111080 \
--admin-username azureuser \
--generate-ssh-keys
Availability
Availability set
Troubleshooting
Troubleshoot VM creation
The Resource 'Microsoft.Compute/virtualMachines/perf-test' under resource group 'XXX' was not found
Run the command again.
./create_vm_in_state_set.sh
{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"NotFound","message":"{\r\n \"error\": {\r\n \"code\": \"ResourceNotFound\",\r\n \"message\": \"The Resource 'Microsoft.Compute/virtualMachines/perf-test' under resource group 'XXX' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix\"\r\n }\r\n}"}]}}
Addition of a VM with managed disks to non-managed Availability Set or addition of a VM with blob based disks to managed Availability Set is not supported
Addition of a VM with managed disks to non-managed Availability Set or addition of a VM with blob based disks to managed Availability Set is not supported. Please create an Availability Set with 'Aligned' SKU in order to add a VM with managed disks to it.