0
0
Azurecloud~5 mins

Traffic Manager routing methods in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Traffic Manager helps direct internet traffic to different servers or services based on rules. It solves the problem of sending users to the best or closest server to improve speed and reliability.
When you want to send users to the closest server to reduce loading time.
When you want to balance traffic evenly across multiple servers to avoid overload.
When you want to send traffic only to healthy servers to avoid downtime.
When you want to prioritize one server but use others as backup if it fails.
When you want to distribute traffic based on geographic location of users.
Config File - traffic-manager-profile.json
traffic-manager-profile.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Network/trafficManagerProfiles",
      "apiVersion": "2021-02-01",
      "name": "myTrafficManager",
      "location": "global",
      "properties": {
        "profileStatus": "Enabled",
        "trafficRoutingMethod": "Performance",
        "dnsConfig": {
          "relativeName": "mytrafficmanager",
          "ttl": 30
        },
        "monitorConfig": {
          "protocol": "HTTP",
          "port": 80,
          "path": "/"
        },
        "endpoints": [
          {
            "name": "endpoint1",
            "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints",
            "properties": {
              "targetResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myApp1",
              "endpointStatus": "Enabled",
              "weight": 10,
              "endpointLocation": "eastus"
            }
          },
          {
            "name": "endpoint2",
            "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints",
            "properties": {
              "targetResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myApp2",
              "endpointStatus": "Enabled",
              "weight": 20,
              "endpointLocation": "westus"
            }
          }
        ]
      }
    }
  ]
}

This JSON defines an Azure Traffic Manager profile named myTrafficManager.

trafficRoutingMethod sets how traffic is routed; here it is Performance to send users to the closest endpoint.

dnsConfig sets the DNS name and time-to-live for caching.

monitorConfig defines how Traffic Manager checks if endpoints are healthy.

endpoints lists the servers or services to route traffic to, with details like location and weight.

Commands
This command creates a Traffic Manager profile named 'myTrafficManager' in the resource group 'myResourceGroup' using the Performance routing method. It sets the DNS name and health probe details.
Terminal
az network traffic-manager profile create --name myTrafficManager --resource-group myResourceGroup --routing-method Performance --unique-dns-name mytrafficmanager --ttl 30 --protocol HTTP --port 80 --path /
Expected OutputExpected
{ "dnsConfig": { "relativeName": "mytrafficmanager", "ttl": 30 }, "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/trafficManagerProfiles/myTrafficManager", "location": "global", "name": "myTrafficManager", "profileStatus": "Enabled", "trafficRoutingMethod": "Performance", "monitorConfig": { "path": "/", "port": 80, "protocol": "HTTP" }, "resourceGroup": "myResourceGroup", "type": "Microsoft.Network/trafficManagerProfiles" }
--routing-method - Sets how Traffic Manager routes traffic (Performance, Priority, Weighted, Geographic, etc.)
--unique-dns-name - Sets the DNS name for the Traffic Manager profile
This command adds an endpoint named 'endpoint1' to the Traffic Manager profile. It points to an Azure web app in East US with weight 10, used in Weighted routing.
Terminal
az network traffic-manager endpoint create --resource-group myResourceGroup --profile-name myTrafficManager --name endpoint1 --type azureEndpoints --target-resource-id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myApp1 --endpoint-location eastus --weight 10
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/trafficManagerProfiles/myTrafficManager/azureEndpoints/endpoint1", "name": "endpoint1", "properties": { "endpointStatus": "Enabled", "endpointLocation": "eastus", "weight": 10, "targetResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myApp1" }, "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints" }
--weight - Sets the weight of the endpoint for Weighted routing
--endpoint-location - Specifies the geographic location of the endpoint
This command adds a second endpoint named 'endpoint2' in West US with weight 20, used in Weighted routing.
Terminal
az network traffic-manager endpoint create --resource-group myResourceGroup --profile-name myTrafficManager --name endpoint2 --type azureEndpoints --target-resource-id /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myApp2 --endpoint-location westus --weight 20
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Network/trafficManagerProfiles/myTrafficManager/azureEndpoints/endpoint2", "name": "endpoint2", "properties": { "endpointStatus": "Enabled", "endpointLocation": "westus", "weight": 20, "targetResourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myApp2" }, "type": "Microsoft.Network/trafficManagerProfiles/azureEndpoints" }
--weight - Sets the weight of the endpoint for Weighted routing
This command shows the details of the Traffic Manager profile to verify its configuration and endpoints.
Terminal
az network traffic-manager profile show --name myTrafficManager --resource-group myResourceGroup
Expected OutputExpected
{ "name": "myTrafficManager", "resourceGroup": "myResourceGroup", "trafficRoutingMethod": "Performance", "dnsConfig": { "relativeName": "mytrafficmanager", "ttl": 30 }, "monitorConfig": { "protocol": "HTTP", "port": 80, "path": "/" }, "endpoints": [ { "name": "endpoint1", "properties": { "endpointStatus": "Enabled", "endpointLocation": "eastus" } }, { "name": "endpoint2", "properties": { "endpointStatus": "Enabled", "endpointLocation": "westus" } } ] }
Key Concept

If you remember nothing else from this pattern, remember: Traffic Manager routes user traffic based on rules like location, priority, or weight to send users to the best available endpoint.

Common Mistakes
Setting routing method but forgetting to add endpoints.
Traffic Manager needs endpoints to route traffic; without them, it cannot send users anywhere.
Always add at least one endpoint after creating the Traffic Manager profile.
Using Priority routing but assigning the same priority to multiple endpoints.
Priority routing requires unique priorities to decide which endpoint is primary and which are backups.
Assign distinct priority numbers to endpoints when using Priority routing.
Not configuring health probes correctly, so Traffic Manager thinks endpoints are down.
Incorrect health probe settings cause Traffic Manager to mark healthy endpoints as unhealthy, disrupting traffic flow.
Set correct protocol, port, and path in monitorConfig to match the actual endpoint health check.
Summary
Create a Traffic Manager profile with a routing method and health probe settings.
Add endpoints with details like location, priority, or weight depending on routing method.
Verify the profile and endpoints to ensure Traffic Manager routes traffic correctly.