Azure App Service: How to connect to the Kudu site of a specific instance
Every Azure Web App has an associated 'scm' service site, which runs Kudu and other Site Extensions.
- Kudu site can be accessed using either of these credentials
- Single Sign-on
- User-level credentials (aka Deployment Credentials)
- Site-level credentials (aka Publish Profile Credentials)
- Kudu site always connect to a single instance. E.g. If the site is hosted in an App Service plan which is scaled out to 3 instances, then at any time the KUDU will always connect to one instance only.
Here is a simple request flow of an Azure Web App
The front-end uses ARRAffinity cookie to affinitize the request to specific instances. This cookie can be disabled if needed. Refer this on how disable ARR Affinity.
The ARRAffinity cookie is unique and corresponds to an instance. If there are multiple instances, then there will be ARRAffinity cookie corresponding to those many instances. So we can modify the ARRAffinity cookie in the HTTP response and force KUDU to connect to a specific instance.
- Browser: Chrome/Firefox/Opera or any other browser which has extensions that allows you to edit cookies.
- Extension: EditThisCookie (Chrome) | EditThisCookie (Opera)
DETERMINE THE ARRAFFINITY COOKIE OF AN INSTANCE
- Browse to https://resources.azure.com/ (Azure Resource Explorer)
- In the search window enter the name of the web app. See the following screenshot for reference:
- If there are other Azure resources with similar names, select the resource of type “Microsoft.Web/sites”
- In the left side panel, expand “instances” and this would load all the instances on which the web app is hosted. The instance name displayed is also the value of the ARRAffinity cookie.
In the above image the site kaushalp is scaled out to 2 instances. So we have 2 instance id’s which are beginning with:
CONNECT TO THE KUDU CONSOLE OF A SPECIFIC INSTANCE
- For this we need to have a tool which allows us to modify the cookies
- There are multiple ways to do this.
- I am using EditThisCookie extension in chrome browser. Here is the link to install this: Install EditThisCookie
- Now, browse to the KUDU site of your web app: https://<sitename>.scm.azurewebsites.net (replace <sitename> with name of the web app)
- Click on Environment.
- Under System info, the “instance id” value determines the instance to which the KUDU is connected. In the screenshot below, the kudu site is connected to the instance whose short instance id is bac64d.
- We can use one of the instances value we obtained via ARM explorer to force KUDU to connect to a specific site.
(Here we are connecting to the instance with the id beginning with “bac64d” )
- In the browser window click on EditThisCookie icon (next to the Address bar) .
- In the pop-up, click on ARRAffinity
- Replace the value with the instance id that you need to connect to
- Click on the tick mark to save the cookie and then refresh the page.
It should have connected to other instance. To confirm, browse to Environment and under System Info the value of Instance id should match the value that was entered earlier.