baiyun@Azure:~$ version=$(az aks get-versions -l eastus --query 'orchestrators[-1].orchestratorVersion' -o tsv) baiyun@Azure:~$ az group create --name akshandsonlab2 --location eastus baiyun@Azure:~$ az aks create --resource-group akshandsonlab --name hansakscluster20201 --enable-addons monitoring --kubernetes-version $version --generate-ssh-keys --location eastus baiyun@Azure:~$ az acr create --resource-group akshandsonlab --name hansacr2020 --sku Standard --location eastus baiyun@Azure:~$ AKS_RESOURCE_GROUP="akshandsonlab" baiyun@Azure:~$ AKS_CLUSTER_NAME="hansakscluster2020" baiyun@Azure:~$ ACR_RESOURCE_GROUP="akshandsonlab" baiyun@Azure:~$ ACR_NAME="hansacr2020" baiyun@Azure:~$ CLIENT_ID=$(az aks show --resource-group $AKS_RESOURCE_GROUP --name $AKS_CLUSTER_NAME --query "servicePrincipalProfile.clientId" --output tsv) baiyun@Azure:~$ ACR_ID=$(az acr show --name $ACR_NAME --resource-group $ACR_RESOURCE_GROUP --query "id" --output tsv) baiyun@Azure:~$ az role assignment create --assignee $CLIENT_ID --role acrpull --scope $ACR_ID baiyun@Azure:~$ az sql server create -l eastus -g akshandsonlab -n hanssqlserver2020 -u sqladmin -p P2ssw0rd1234 baiyun@Azure:~$ az sql db create -g akshandsonlab -s hanssqlserver2020 -n mhcdb --service-objective S0 check names on https://portal.azure.com/: Server name: hanssqlserver2020.database.windows.net Login server: hansacr2020.azurecr.io baiyun@Azure:~$ az aks get-credentials --resource-group akshandsonlab --name hansakscluster2020 Merged "hansakscluster2020" as current context in /home/baiyun/.kube/config baiyun@Azure:~$ kubectl get nodes NAME STATUS ROLES AGE VERSION aks-nodepool1-32402993-vmss000000 Ready agent 31m v1.19.0 aks-nodepool1-32402993-vmss000001 Ready agent 31m v1.19.0 aks-nodepool1-32402993-vmss000002 Ready agent 31m v1.19.0
How to use File Storage transfer files to Azure clouddrive
- create a Azure Storage Account and File Storage first, then click “Connect” to get connection Credential
2. open a PowerShell on local computer, run the commands copied from first step:
# Save the password so the drive will persist on reboot
cmd.exe /C "cmdkey /add:`"hansstorage123.file.core.windows.net`" /user:`"Azure\hansstorage123`" /pass:`"hwvpQAhkRVsfjOLmYS1cpuIbMhsk5MK+0cZHaZwm6xpEj1Lke5jJEyU2Uxz4B4QKFLLaMcgyUQvQE0VzkxtGxA==`""
# Mount the drive
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\hansstorage123.file.core.windows.net\az30302a-share" -Persist
3. then you can copy files to Z: driver
4. run below command on Azure PowerShell window, you will find all the files in Z: mounted to your Azure:~/clouddrive
$subscription_id = (Get-AzContext).Subscription.id clouddrive mount -s "$subscription_id" -g 'az30302a-labRG' -n 'hansstorage123' -f 'az30302a-share'
or you can use git clone your repository to your Azure:~/clouddrive.
List or remove Azure resources with Bash or PowerShell
Bash:
list: az group list --query "[?starts_with(name,'az30301a-')]".name --output tsv remove: az group list --query "[?starts_with(name,'az30301a-')]".name --output tsv | xargs -L1 bash -c 'az group delete --name $0 --no-wait --yes'
PowerShell:
list: Get-AzResourceGroup -Name ‘*’ remove: Get-AzResourceGroup -Name ‘*’ | Remove-AzResourceGroup -Force -AsJob
Deploy with template and parameters file:
az deployment group create \ --resource-group az30301b-testRG \ --template-file azuredeploy30301rgb.json \ --parameters @azuredeploy30301rgb.parameters.json
Azure Template deployment and RGs clean
- we can create a VM with a simple template:
New-AzResourceGroupDeployment -ResourceGroupName myResourceGroup -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-windows/azuredeploy.json
2. we can try to create our own template file azuredeploy.json:
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2019-04-01", "name": "{provide-unique-name}", "location": "eastus", "sku": { "name": "Standard_LRS" }, "kind": "StorageV2", "properties": { "supportsHttpsTrafficOnly": true } } ] }
create resource with commands:
1. create a new ResourceGroup New-AzResourceGroup ` -Name myResourceGroup ` -Location "Central US" 2. addstorage $templateFile = "azuredeploy.json" New-AzResourceGroupDeployment ` -Name addstorage ` -ResourceGroupName myResourceGroup ` -TemplateFile $templateFile
3. you can delete ALL ResourceGroups with command:
Get-AzResourceGroup -Name ‘*’ | Remove-AzResourceGroup -Force -AsJob
install Azure PowerShell on Windows10
get steps from https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-4.7.0, Installing the module for all users on a system requires elevated privileges. Start the PowerShell session using Run as administrator in Windows or use the sudo
command on macOS or Linux:
1. install the Azure PowerShell: if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) { Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' + 'Az modules installed at the same time is not supported.') } else { Install-Module -Name Az -AllowClobber -Scope AllUsers } 2. run Connect-AzAccount to login PS C:\Windows\system32> Connect-AzAccount Connect-AzAccount : The 'Connect-AzAccount' command was found in the module 'Az.Accounts', but the module could not be loaded. For more information, run 'Import-Module Az.Accounts'. At line:1 char:1 + Connect-AzAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-AzAccount:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule 3. run Set-ExecutionPolicy RemoteSigned to fix the issue PS C:\Windows\system32> Set-ExecutionPolicy RemoteSigned 4. run Connect-AzAccount to login again: PS C:\Windows\system32> Connect-AzAccount Account SubscriptionName TenantId Environment ------- ---------------- -------- ----------- zhuby1973@outlook.com Azure Pass - Sponsorship 2b73972d-b7ec-4ec6-a9ae-84471a4aacd7 AzureCloud 5. run Get-AzResourceGroup to get your ResourceGroup list PS C:\Windows\system32> Get-AzResourceGroup -Name '*'
Create a Python app in Azure App Service on Linux
make sure you have python3 and Azure CLI installed on Windows:
C:\Users\zhuby>python --version Python 3.8.3 C:\Users\zhuby>az --version azure-cli 2.12.0
Then sign in to Azure through the CLI: az login
Clone the sample code, setup venv and deploy to local/Azure:
C:\Users\zhuby>git clone https://github.com/Azure-Samples/python-docs-hello-world C:\Users\zhuby>cd python-docs-hello-world C:\Users\zhuby\python-docs-hello-world>python -m venv venv C:\Users\zhuby\python-docs-hello-world>venv\Scripts\activate.bat (venv) C:\Users\zhuby\python-docs-hello-world>pip install -r requirements.txt (venv) C:\Users\zhuby\python-docs-hello-world>flask run (venv) C:\Users\zhuby\python-docs-hello-world>az webapp up --sku F1 -n python0508 The webapp 'python0508' doesn't exist Creating Resource group 'zhuby1973_rg_Linux_centralus' ... Resource group creation complete Creating AppServicePlan 'zhuby1973_asp_Linux_centralus_0' ... Creating webapp 'python0508' ... Configuring default logging for the app, if not already enabled Creating zip with contents of dir C:\Users\zhuby\python-docs-hello-world ... Getting scm site credentials for zip deployment Starting zip deployment. This operation can take a while to complete ... Deployment endpoint responded with status code 202 You can launch the app at http://python0508.azurewebsites.net { "URL": "http://python0508.azurewebsites.net", "appserviceplan": "zhuby1973_asp_Linux_centralus_0", "location": "centralus", "name": "python0508", "os": "Linux", "resourcegroup": "zhuby1973_rg_Linux_centralus", "runtime_version": "python|3.7", "runtime_version_detected": "-", "sku": "FREE", "src_path": "C:\\Users\\zhuby\\python-docs-hello-world" }
you can redeploy updates, edit the app.py with below:
def hello(): print("Handling request to home page.") return "Hello, Azure!"
Redeploy the app using the az webapp up
command again! you will get update the webpage.
To stream logs, run the az webapp log tail command.