Use the Azure CLI to create a Traffic Manager profile in Azure for a highly available webapp

%3CLINGO-SUB%20id%3D%22lingo-sub-1791902%22%20slang%3D%22en-US%22%3EUse%20the%20Azure%20CLI%20to%20create%20a%20Traffic%20Manager%20profile%20in%20Azure%20for%20a%20highly%20available%20webapp%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1791902%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Azure%20friends%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EStart%20the%20CloudShell%20in%20the%20Azure%20portal%26nbsp%3Bor%20go%20to%20the%20following%20URL%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fshell.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fshell.azure.com%2F%3C%2FA%3E%3C%2FP%3E%3CP%3EPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%20deployment%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Here%20you%20can%20find%20out%20which%20subscription%20you%20are%20working%20with%3CBR%20%2F%3E%3CSTRONG%3Eaz%20account%20show%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23View%20all%20subscriptions%3CBR%20%2F%3E%3CSTRONG%3Eaz%20account%20list%20--all%20--output%20table%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23change%20the%20subscription%20(if%20necessary)%3CBR%20%2F%3E%3CSTRONG%3Eaz%20account%20set%20--subscription%20%22Name%20of%20the%20Subscription%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Create%20a%20resource%20group%3CBR%20%2F%3E%3CSTRONG%3Eaz%20group%20create%20--name%20myResourceGroup%20--location%20westeurope%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Create%20a%20Traffic%20Manager%20profile%3CBR%20%2F%3E%3CSTRONG%3Eaz%20network%20traffic-manager%20profile%20create%20--name%20twtmpcloud2020%20--resource-group%20myResourceGroup%20--routing-method%20Priority%20--path%20%22%2F%22%20--protocol%20HTTP%20--unique-dns-name%20twtmpcloud2020%20--ttl%2030%20--port%2080%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Create%20web%20app%20service%20plans%3CBR%20%2F%3E%3CSTRONG%3Eaz%20appservice%20plan%20create%20--name%20twwebappeastus%20--resource-group%20myResourceGroup%20--location%20eastus%20--sku%20S1%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3Eaz%20appservice%20plan%20create%20--name%20twwebappwesteurope%20--resource-group%20myResourceGroup%20--location%20westeurope%20--sku%20S1%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Create%20a%20web%20app%20in%20the%20app%20service%20plan%3CBR%20%2F%3E%3CSTRONG%3Eaz%20webapp%20create%20--name%20twapp1eastus%20--plan%20twwebappeastus%20--resource-group%20myResourceGroup%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3Eaz%20webapp%20create%20--name%20twapp2westeurope%20--plan%20twwebappwesteurope%20--resource-group%20myResourceGroup%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Add%20Traffic%20Manager%20endpoints%20(East%20US%20endpoint)%3CBR%20%2F%3E%3CSTRONG%3Eaz%20webapp%20show%20--name%20twapp1eastus%20--resource-group%20myResourceGroup%20--query%20id%20%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%23Make%20note%20of%20ID%20displayed%3C%2FP%3E%3CP%3E%3CSTRONG%3Eaz%20network%20traffic-manager%20endpoint%20create%20--name%20twapp1eastus%20--resource-group%20myResourceGroup%20--profile-name%20twtmpcloud2020%20--type%20azureEndpoints%20--target-resource-id%20%3CID%20from%3D%22%22%20az%3D%22%22%20webapp%3D%22%22%20show%3D%22%22%3E%20--priority%201%20--endpoint-status%20Enabled%3C%2FID%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Add%20Traffic%20Manager%20endpoints%20(West%20Europe%20endpoint)%3CBR%20%2F%3E%3CSTRONG%3Eaz%20webapp%20show%20--name%20twapp2westeurope%20--resource-group%20myResourceGroup%20--query%20id%20%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%23Make%20note%20of%20ID%20displayed%3C%2FP%3E%3CP%3E%3CSTRONG%3Eaz%20network%20traffic-manager%20endpoint%20create%20--name%20twapp2westeurope%20--resource-group%20myResourceGroup%20--profile-name%20twtmpcloud2020%20--type%20azureEndpoints%20--target-resource-id%20%3CID%20from%3D%22%22%20az%3D%22%22%20webapp%3D%22%22%20show%3D%22%22%3E%20--priority%202%20--endpoint-status%20Enabled%3C%2FID%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Test%20your%20Traffic%20Manager%20profile%20(Determine%20the%20DNS%20name)%3CBR%20%2F%3E%3CSTRONG%3Eaz%20network%20traffic-manager%20profile%20show%20--name%20twtmpcloud2020%20--resource-group%20myResourceGroup%20--query%20dnsConfig.fqdn%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23In%20the%20Portal%20modify%20the%20text%20in%20one%20azure%20app%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Copy%20the%20DNS%20name%20of%20your%20Traffic%20Manager%20profile%20(http%3A%2F%2F%3CRELATIVEDNSNAME%3E.trafficmanager.net)%20to%20view%20the%20website%20in%20a%20new%20web%20browser%20session%3C%2FRELATIVEDNSNAME%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23To%20view%20Traffic%20Manager%20failover%20in%20action%3CBR%20%2F%3E%3CSTRONG%3Eaz%20network%20traffic-manager%20endpoint%20update%20--name%20twapp1eastus%20--resource-group%20myResourceGroup%20--profile-name%20twtmpcloud2020%20--type%20azureEndpoints%20--endpoint-status%20Disabled%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Copy%20the%20DNS%20name%20of%20your%20Traffic%20Manager%20profile%20(http%3A%2F%2F%3CRELATIVEDNSNAME%3E.trafficmanager.net)%20to%20view%20the%20website%20in%20a%20new%20web%20browser%20session%3C%2FRELATIVEDNSNAME%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20you%20have%20configured%20a%20Traffic%20Manager%20Profile%2C%20two%20App%20Service%20Plans%20and%20WebApp's%20with%20the%20Azure%20CLI!%20Congratulations!%20If%20you%20don't%20need%20the%20resource%20group%20(also%20to%20save%20costs)%20don't%20forget%20the%20clean%20up.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Clean%20Up%20(if%20necessary)%3CBR%20%2F%3E%3CSTRONG%3Eaz%20group%20delete%20--resource-group%20myResourceGroup%20--yes%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F73893%22%20target%3D%22_blank%22%3E%40azure%3C%2FA%3E%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
MVP

 

Hi Azure friends,

 

Start the CloudShell in the Azure portal or go to the following URL: https://shell.azure.com/

Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#Here you can find out which subscription you are working with
az account show

 

#View all subscriptions
az account list --all --output table

 

#change the subscription (if necessary)
az account set --subscription "Name of the Subscription"

 

#Create a resource group
az group create --name myResourceGroup --location westeurope

 

#Create a Traffic Manager profile
az network traffic-manager profile create --name twtmpcloud2020 --resource-group myResourceGroup --routing-method Priority --path "/" --protocol HTTP --unique-dns-name twtmpcloud2020 --ttl 30 --port 80

 

#Create web app service plans
az appservice plan create --name twwebappeastus --resource-group myResourceGroup --location eastus --sku S1

 

az appservice plan create --name twwebappwesteurope --resource-group myResourceGroup --location westeurope --sku S1

 

#Create a web app in the app service plan
az webapp create --name twapp1eastus --plan twwebappeastus --resource-group myResourceGroup

 

az webapp create --name twapp2westeurope --plan twwebappwesteurope --resource-group myResourceGroup

 

#Add Traffic Manager endpoints (East US endpoint)
az webapp show --name twapp1eastus --resource-group myResourceGroup --query id

#Make note of ID displayed

az network traffic-manager endpoint create --name twapp1eastus --resource-group myResourceGroup --profile-name twtmpcloud2020 --type azureEndpoints --target-resource-id <ID from az webapp show> --priority 1 --endpoint-status Enabled

 

#Add Traffic Manager endpoints (West Europe endpoint)
az webapp show --name twapp2westeurope --resource-group myResourceGroup --query id

#Make note of ID displayed

az network traffic-manager endpoint create --name twapp2westeurope --resource-group myResourceGroup --profile-name twtmpcloud2020 --type azureEndpoints --target-resource-id <ID from az webapp show> --priority 2 --endpoint-status Enabled

 

#Test your Traffic Manager profile (Determine the DNS name)
az network traffic-manager profile show --name twtmpcloud2020 --resource-group myResourceGroup --query dnsConfig.fqdn

 

#In the Portal modify the text in one azure app

 

#Copy the DNS name of your Traffic Manager profile (http://<relativednsname>.trafficmanager.net) to view the website in a new web browser session

 

#To view Traffic Manager failover in action
az network traffic-manager endpoint update --name twapp1eastus --resource-group myResourceGroup --profile-name twtmpcloud2020 --type azureEndpoints --endpoint-status Disabled

 

#Copy the DNS name of your Traffic Manager profile (http://<relativednsname>.trafficmanager.net) to view the website in a new web browser session

 

Now you have configured a Traffic Manager Profile, two App Service Plans and WebApp's with the Azure CLI! Congratulations! If you don't need the resource group (also to save costs) don't forget the clean up.

 

#Clean Up (if necessary)
az group delete --resource-group myResourceGroup --yes

 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, @azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

0 Replies