Skip to content

Instantly share code, notes, and snippets.

@haray-isao
Last active July 23, 2019 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haray-isao/b5c7ce14fb456c9cf9df2bbe1abb59f5 to your computer and use it in GitHub Desktop.
Save haray-isao/b5c7ce14fb456c9cf9df2bbe1abb59f5 to your computer and use it in GitHub Desktop.

Azure CLI Examples

Select your subscription

List subscriptions your have access to.

az account list
az account list –-output table
az account list –o table

Select subscription.

az account set --subscription [subscription-id]

Create a Linux VM

Create a new resource group and Linux VM.

az group create --location southeastasia --name MyRG
az vm create -n [myVM] -g [MyRG] --image UbuntuLTS --generate-ssh-keys
az vm list-ip-addresses –n [myVM] –g [MyRG]
ssh [your-ip-address]

List available images on Azure

az vm image list -o table

Cleaning up

az group delete -n [MyRG]

Deploy a PHP App to App Service

# Create a resource group
az group create --name [myResourceGroup] --location [southeastasia]
# Create an Azure App Service plan
az appservice plan create --name [myAppServicePlan] --resource-group [myResourceGroup] --sku S1
# Create a web app
az webapp create --name [app name] --resource-group [myResourceGroup] --plan [myAppServicePlan]
# Deploy code from a public GitHub repository. 
az webapp deployment source config --name [app name] --resource-group [myResourceGroup] --repo-url https://github.com/Azure-Samples/php-docs-hello-world --branch master --manual-integration
# Browse the app
curl http://[app name].azurewebsites.net/
# Cleaning up
az group delete --name [myResourceGroup]

Deploy a PHP App to App Service on Linux

# Create a resource group
az group create --name [myResourceGroup] --location [southeastasia]
# Create an Azure App Service plan
az appservice plan create --name [myAppServicePlan] --resource-group [myResourceGroup] --sku S1 --is-linux
# Create a web app
az webapp create --name [app name] --resource-group [myResourceGroup] --plan [myAppServicePlan] --runtime "php|7.2"
# Deploy code from a public GitHub repository. 
az webapp deployment source config --name [app name] --resource-group [myResourceGroup] --repo-url https://github.com/Azure-Samples/php-docs-hello-world --branch master --manual-integration
# Browse the app
curl http://[app name].azurewebsites.net/
# Cleaning up
az group delete --name [myResourceGroup]

Deploy a Custom image to Web App for Containers

# Create a resource group
az group create --name [myResourceGroup] --location [southeastasia]
# Create an Azure App Service plan
az appservice plan create --name [myAppServicePlan] --resource-group [myResourceGroup] --sku S1 --is-linux
# Create a web app
az webapp create --resource-group [myResourceGroup] --plan [myAppServicePlan] --name [app name] --deployment-container-image-name microsoft/azure-appservices-go-quickstart
# Browse the app
curl http://[app name].azurewebsites.net/hello
# Cleaning up
az group delete --name [myResourceGroup]

List available location

az account list-locations -o table
az appservice list-locations --linux-workers-enabled --sku B1 -o table

Available App Service plan SKU

--sku {
	Free : F1, FREE, 
	Shared :  D1, SHARED,
	Basic : B1, B2, B3,
 	Standard : S1, S2, S3
	Premium : P1, P1V2, P2, P2V2, P3, P3V2, 
}

Deploy an Azure Container Service (AKS) cluster

# Create k8s definition yaml
vi azure-vote.yaml
# Create a resource group
az group create --name [myResourceGroup] --location eastus
# Create AKS cluster
az aks create --resource-group [myResourceGroup] --name [myAKSCluster] --node-count 1 --generate-ssh-keys
# Connect to the cluster
az aks install-cli
az aks get-credentials --resource-group [myResourceGroup] --name [myAKSCluster]
kubectl get nodes
# Run the application
kubectl create -f azure-vote.yaml
kubectl get service azure-vote-front --watch
# Cleaning up
az group delete -n [myResourceGroup]

azure-vote.yaml

Deploy sample container to ACI

# Create a resource group
az group create --name [myResourceGroup] --location [eastus]
# Create a Container
az container create --resource-group [myResourceGroup] --name [mycontainer] --image microsoft/aci-helloworld --dns-name-label [aci-demo] --ports 80
# Show provisioning status
watch -n 1 az container show --resource-group [myResourceGroup] --name [mycontainer] --query "{FQDN:ipAddress.fqdn,ProvisioningState:provisioningState}" --out table
# Once the container moves to the Succeeded state, you can reach it in your browser by navigating to its FQDN
# Cleaning up
az group delete -n [myResourceGroup]

Azure Database for MySQL

# Create a resource group
az group create --name [myresourcegroup] --location [southeastasia]
# Create an Azure Database for MySQL server
# “--sku-name” is “tier + family + cores” e.g. B_Gen4_1, GP_Gen5_8
az mysql server create --location [southeastasia] --resource-group [myresourcegroup] --name [myservername] --admin-user [myadmin] --admin-password [server_admin_password] --sku-name GP_Gen4_2 --version 5.7
# Configure firewall rule
az mysql server firewall-rule create --resource-group [myresourcegroup] --server [myservername] --name AllowYourIP --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
# Get the connection information
# Make a note of the FQDN and administratorLogin.
az mysql server show --resource-group [myresourcegroup] --name [myservername]
# Connect to the server using the mysql.exe command
mysql -h [myservername].mysql.database.azure.com -u myadmin@ <myservername> -p
mysql> status
# Cleaning up
az group delete -n [myResourceGroup]

Azure Database for PostgreSQL

# Create a resource group
az group create --name [myresourcegroup] --location [southeastasia]
# Create an Azure Database for PostgreSQL server
# “--sku-name” is “tier + family + cores” e.g. B_Gen4_1, GP_Gen5_8
az postgres server create --location [southeastasia] --resource-group [myresourcegroup] --name [myservername] --admin-user [myadmin] --admin-password [server_admin_password] --sku-name GP_Gen5_2 --version 9.6
# Configure firewall rule
az postgres server firewall-rule create --resource-group [myresourcegroup] --server [myservername] --name AllowYourIP --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
# Get the connection information
# Make a note of the FQDN and administratorLogin.
az postgres server show --resource-group [myresourcegroup] --name [myservername]
# Connect to the server using the psql command
psql --host=[myservername].postgres.database.azure.com --port=5432 --username=[user@myservername] --dbname=postgres
# Cleaning up
az group delete -n [myResourceGroup]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment