iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
👥

Accessing Specific App Service Kudu Instances

に公開

Introduction

This is a continuation of the following article:

https://zenn.dev/georgeosddev/articles/azure-appservice-kudu-access-from-cli

In the previous article, we retrieved the local disk usage using the method below.

az rest --only-show-errors --method post --url "https://$sitename.scm.azurewebsites.net/Env.cshtml" --resource "https://management.azure.com" \
| htmlq 'h3#sysInfo + ul li' --text \
| jq -R -s 'split("\n") | map(select(length>0)) | map(select(test(": "))) | map(capture("^(?<k>.*?):\\s+(?<v>.*)$") |{"key": .k, "value": .v})' \
| jq '.[] | select(.key=="C:\\local usage")'

# Output
{
  "key": "C:\\local usage",
  "value": "11,264 MB total; 11,111 MB free"
}

When scaled out with multiple instances

Accessing via the Web UI

You can access a specific instance by selecting it in the upper-right corner of the screen. You can see that C:\local usage differs for each instance.

instance_1

instance_2

Accessing a specific instance via CLI

App Service internally uses IIS ARR (Application Request Routing) to distribute requests to instances. By setting the ARRAffinity cookie to an instance ID (the name retrieved via az webapp list-instances), requests are routed to that specific instance. This mechanism is independent of the ARR Affinity setting for the main site (clientAffinityEnabled) and is applicable to the Kudu (SCM) site.

Reference

Let's give it a try.

rgname=ResourceGroupName
sitename=SiteName

az webapp list-instances --name "$sitename" --resource-group "$rgname" --query '[].name' -o tsv \
| while read -r instanceId; do
  echo "=== Instance: $instanceId ==="
  az rest --only-show-errors --method post \
    --url "https://$sitename.scm.azurewebsites.net/Env.cshtml" \
    --resource "https://management.azure.com" \
    --headers "Cookie=ARRAffinity=$instanceId" \
  | htmlq 'h3#sysInfo + ul li' --text \
  | jq -R -s 'split("\n") | map(select(length>0)) | map(select(test(": "))) | map(capture("^(?<k>.*?):\\s+(?<v>.*)$") |{"key": .k, "value": .v})' \
  | jq '.[] | select(.key=="C:\\local usage")'
done

# Output
=== Instance: 82a33e5b87c862ee73c02348dc8feed5583ee2448f26f523a39592e7a6b52856 ===
{
  "key": "C:\\local usage",
  "value": "11,264 MB total; 11,112 MB free"
}
=== Instance: c738a57f57a41ab01a2c0db0a8df45953ac19adf187ed99418fb66a91a1fb5bb ===
{
  "key": "C:\\local usage",
  "value": "11,264 MB total; 11,192 MB free"
}
=== Instance: e5d89797ff86138b1ab5001da08dac0378b84620ebc2a4140fe2964ef3cb1a40 ===
{
  "key": "C:\\local usage",
  "value": "11,264 MB total; 10,960 MB free"
}

We confirmed that the C:\local usage value differs for each instance.

Summary

  • You can retrieve a list of instance IDs for a scaled-out environment using az webapp list-instances.
  • You can route requests to the Kudu SCM site to a specific instance by specifying the instance ID in the ARRAffinity cookie.
  • This allows you to retrieve information such as local disk usage for each instance via the CLI.

Discussion