Azure App Service with several instances
A worked installation of the Server on Azure App Service with two or more instances, from an empty resource group to a console you can sign in to. It needs Server 1.32.0 or later, the first version whose instances can reach each other. Read Azure App Service first: this page follows its order, points back to it where a step is the same, and says only what several instances add or change.
What was run. This guide was written from a first deployment of Server 1.32.0 with two instances on a B1 plan, an Azure Managed Redis and a database in an elastic pool of an existing Azure SQL server. That deployment started, both instances registered and connected to Redis, and the console answered on a custom domain. It had no Workstation connected yet, so no call had crossed from one instance to the other there, no signature had been made, and no load was measured. It had also run for less than a day, so the renewal of the token the app signs in to Redis with, which lasts 24 hours, had not been seen. Treat your own first deployment as a test, and read What the first deployment met before you start.
What you end up with
| Resource | Example name | Notes |
|---|---|---|
| Resource group | tb-prod | Everything below, unless you place the database elsewhere |
| App Service plan | tb-prod-plan | Linux, two or more workers, never Free |
| App Service | tb-prod | The Server, one container per worker |
| Azure Managed Redis | tb-prod-redis | How the instances reach each other. It holds no state |
| Azure SQL database | TrustBridge | On a server of its own, or on one you already run |
| Managed certificate | your custom domain | Issued and renewed by App Service |
| Application Insights and its workspace | tb-prod-insights, tb-prod-logs | Optional, and the only retained copy of the log |
The app signs in to the database, to the registry and to Redis with its own managed identity. There is no database password, no registry password and no Redis key anywhere in this deployment.
Before you start
- The Azure CLI, signed in with rights to create resources in the group, and its
redisenterpriseextension, which is how the CLI manages Azure Managed Redis:az extension add --name redisenterprise. - The image,
trustbridge-server:1.32.0or later, in a registry the app can pull from (step 3 of the single-instance page). - The PKI SDK licence, the Signer's address and API key (or the three REST PKI Core values), and the first Administrator's e-mail.
- A Key Ring Protector, minted as the installation page describes. Every instance uses the same one.
- For a database on an existing Azure SQL server: to be its Entra administrator, or a member of the group that is, and a firewall rule that lets your own machine through, because you create the database user from it.
Commands below use these placeholders: <rg>, <plan>, <app>, <cache>, <region>,
<sqlserver>, <database> and <registry>, and a few more that are named where they appear. Pass
--subscription on every command when the
subscription you are deploying into is not your CLI's default; it is safer than switching the
default under your other terminals.
1. The plan, with its instance count
az appservice plan create -g <rg> -n <plan> -l <region> --is-linux --sku P1V3 --number-of-workers 2
--number-of-workers is the instance count. A new deployment can be created with it, as here,
because the app does not start until step 8, by which time it names its Redis. An existing
single-instance deployment is different: add the Redis and the two settings of step 6 first, and
raise the count last.
Size each instance as the single-instance page says. Basic plans run the Server and were not measured; they
have no zone redundancy, which needs a Premium plan. Some of the Server's bounds are each instance's,
so a deployment of two has twice each: the contract throttle, the number of signing runs at once and
the number of release downloads at once. The signature service has to accept the signing bound,
Signing:SignerConcurrency, times the instance count.
2. The database
On a server of its own, follow step 2 of the single-instance page.
On an Azure SQL server you already run, which may be in another resource group or another subscription of the same tenant, create only the database, optionally in one of its elastic pools:
az sql db create -g <sql-rg> -s <sqlserver> -n <database> \
--elastic-pool <pool> --backup-storage-redundancy Local
- Always say the backup redundancy. Left out, the CLI stops to ask whether geo-redundant backups
are meant, and a script has nobody to answer.
Geocopies the backups to the region's pair, which may be in another country;LocalandZonekeep them in the database's region. - The server needs public network access and "Allow Azure services", as on the single-instance page, or a private endpoint with VNet integration. On a shared server, check them rather than change them: they are its owner's.
- A pool's capacity is shared. A migration, or the upload of a Workstation Release of about 100 MB, competes with every other database in the pool.
Use --service-objective in place of --elastic-pool for a database outside a pool.
3 and 4. The image, the app and its identity
Exactly as steps 3 and 4 of the single-instance page, with the 1.32.0 tag.
A registry in another subscription than the app's works, as long as both are of one tenant. The
role assignment is scoped to the registry's id wherever it lives. What changes is the commands: the
CLI finds a registry by name in one subscription only, so each az acr command takes
--subscription with the registry's.
Do not restart the app yet. It cannot start usefully until it has its settings.
5. The instances' Redis
az redisenterprise create -g <rg> --cluster-name <cache> -l <region> --sku Balanced_B1 \
--high-availability Enabled --access-keys-authentication Disabled \
--clustering-policy OSSCluster --public-network-access Enabled
az redisenterprise database access-policy-assignment create -g <rg> --cluster-name <cache> \
--database-name default --access-policy-assignment-name <app-without-hyphens> \
--access-policy-name default \
--object-id $(az webapp identity show -g <rg> -n <app> --query principalId -o tsv)
az redisenterprise show -g <rg> --cluster-name <cache> --query hostName -o tsv
az redisenterprise database show -g <rg> --cluster-name <cache> --query port -o tsv # 10000
- Read the host with
show. The answer ofcreatedid not carry it on the deployment this guide was written from;showdid. - High availability is the point, not an extra. A Redis outage costs every call that crosses from one instance to another until it is back. It costs nothing else: no security bound depends on Redis, and a call that stays on one instance is unaffected.
- The access keys stay disabled. Who can connect is whoever holds an access policy on the cache, which is the app's identity and nobody else. The connection string carries no password.
- The cache is reached on its public endpoint, as Azure SQL is, unless you use VNet integration and a private endpoint. What the instances send each other is sealed under the deployment's key ring, so reading the cache's traffic shows nothing.
OSSClusteris chosen at creation and does not change afterwards.Balanced_B1is a starting point, not a measured figure.Balanced_B0is the smallest size and is what the deployment this guide was written from runs. The instances send each other small messages, one for each call that crosses and one acknowledgement.
6. The database user and the settings
Create the app's identity as a database user exactly as step 5 of the single-instance page says. On a shared server it is a user of your database alone.
Then the settings. They are those of step 6, plus two:
az webapp config appsettings set -g <rg> -n <app> --settings \
Redis__ConnectionString="<cache>.<region>.redis.azure.net:10000,ssl=true" \
Redis__UseManagedIdentity=true
| Setting | Why |
|---|---|
Redis__ConnectionString | The host and port step 5 read back, with ssl=true. Naming a Redis is what makes several instances one deployment. A plan above one worker with no Redis named is the mistake to avoid: nothing refuses it, each instance writes one Critical line and shows a banner on every admin page once it has seen another beside it for longer than a redeploy takes (ten minutes by default), and until it is fixed a session fails against a machine connected to the other instance. |
Redis__UseManagedIdentity=true | The Server signs in to the cache as the app's identity. |
A Redis that cannot be reached never refuses the start: the Server says so once at Critical, shows
a banner on every admin page, keeps serving the calls that stay on one instance, and keeps trying.
7. Pin the platform
az webapp log config -g <rg> -n <app> --docker-container-logging filesystem
az webapp update -g <rg> -n <app> --client-affinity-enabled true --https-only true
az webapp config set -g <rg> -n <app> --always-on true \
--generic-configurations '{"healthCheckPath": "/healthz"}'
Two of these mean something else once there are several instances.
- Client affinity is a requirement, not a convenience. A Workstation's negotiate request and the
connection that follows it must reach the same instance, and so must an Administrator's console.
With affinity off, a machine's connect is answered
404by the instance that did not negotiate it, and the machine never connects. Never turn it off on a deployment of several. - Health Check goes on
/healthz, where one instance keeps it on/. With somewhere to reroute to, App Service takes an instance that cannot reach the database out of rotation and puts it back when it answers again./healthzdoes not ask Redis: a Redis that is down is down for every instance, and taking instances out of rotation cannot help. With the database down every instance is unhealthy; App Service excludes none of them, and still replaces an instance that has been unhealthy for an hour.
8. Start it and check both instances
az webapp restart -g <rg> -n <app>
curl -s https://<app>.azurewebsites.net/healthz # Healthy
az webapp list-instances -g <rg> -n <app> -o table # one row per worker
az webapp log download -g <rg> -n <app> --log-file logs.zip
The first start of an empty database builds the whole schema before anything answers; allow a few
minutes. The downloaded archive has one container log per instance. Read each one, since
/healthz is answered by whichever instance the request reaches. Besides the lines the
single-instance page lists, each instance says:
This Server instance registered as <id> (build 1.32.0).Connected to the Redis Redis:ConnectionString names.This Server instance (<id>) listens for the other instances' requests.
In the console, the Server log screen then names the instance each line came from.
Then sign in, set a real password, enroll the second factor and remove the two Admin__Bootstrap__*
settings, as on the single-instance page.
9. A custom domain and its certificate
Workstations and Administrators should use a name of yours rather than the Azure one.
- In your DNS zone, create a
CNAMEfrom the name to<app>.azurewebsites.net, and aTXTrecordasuid.<name>holding the app's verification id (az webapp show -g <rg> -n <app> --query customDomainVerificationId -o tsv). - Add the hostname, issue a managed certificate and bind it:
az webapp config hostname add -g <rg> --webapp-name <app> --hostname <name>
az webapp config ssl create -g <rg> -n <app> --hostname <name>
az webapp config ssl bind -g <rg> -n <app> --ssl-type SNI \
--certificate-thumbprint <the thumbprint ssl create answered>
The certificate renews itself while the CNAME stays in place. A binding takes a few minutes to
settle: for about four minutes after it, roughly one request in twelve to the custom name failed
its TLS check, the certificate not matching the name, and then none did. Wait before you conclude
anything from one failed request, and give Workstations the custom name as their Server address once
it has settled.
10. Certificate Sign-In
Optional. Two settings turn it on, and the app restarts:
az webapp config appsettings set -g <rg> -n <app> --settings \
Admin__CertificateSignIn__Enabled=true \
Admin__CertificateSignIn__WebPkiLicense="<the Web PKI licence, one-line format>"
- The licence has to name the address people type. One issued for your custom domain does not
cover
<app>.azurewebsites.net, and the certificate page says so as a licence problem when it is opened there. - Nobody signs in with a certificate until somebody has set their Bound CPF, and nobody sets their own: a second Administrator does it on the accounts screen.
- Leave
Admin__CertificateSignIn__Requiredoff until an Administrator has signed in with a certificate. SeeAdmin:CertificateSignIn:Enabledand Certificate Sign-In.
A challenge minted on one instance is honoured by whichever instance receives the answer, so nothing here depends on the instance count.
11. Application Insights
Optional, and worth having: without it the log is kept for a few days on the App Service filesystem and for as long as each container lives.
az extension add --name application-insights # once per machine
az provider register -n Microsoft.OperationalInsights --wait # once per subscription
az provider register -n Microsoft.Insights --wait
az monitor log-analytics workspace create -g <rg> -n <workspace> -l <region> --retention-time 30
az monitor app-insights component create --app <insights> -g <rg> -l <region> \
--workspace <the workspace's resource id> --application-type web
for table in AppTraces AppExceptions; do
az monitor log-analytics workspace table update -g <rg> --workspace-name <workspace> \
-n $table --retention-time 30 --total-retention-time 30
done
az webapp config appsettings set -g <rg> -n <app> --settings \
Logging__ApplicationInsights__ConnectionString="<the component's connection string>"
- Thirty days is the shortest a workspace keeps. Application Insights tables default to ninety whatever the workspace says, so the two the Server's lines land in are set on their own.
- Decide the log level before you pay for the volume. At the image's default every database
command is a log line.
Logging__LogLevel__Default=WarningwithLogging__LogLevel__TrustBridge=Informationkeeps the Server's own lines and drops the rest. Every destination sees the same lines, the container's console output included (Logging:ApplicationInsights:ConnectionString). With those levelsApplication startedis no longer logged, being the framework's line and not the Server's. What then proves a start is the Server's own lines: the protector, the licence, the schema, the vault, and the three instance lines of step 8. - Each line carries the container it came from, so the two instances can be told apart in a query.
Operating it
- The instance count follows the Redis. Once a Redis is named, raise or lower the plan's worker count as load asks, by hand or by an autoscale rule. An instance that starts registers and serves; one that stops ends what it held as it goes, and its machines reconnect to the others.
- What a restart of one instance costs. Its machines reconnect, to any instance. Sessions holding
a Vault Certificate's file password end as
Strandedif that instance held them, and only those; the others carry on, signing through any instance. - Upgrades are two cases. A version with no migration replaces the instances while old and new serve side by side. A version with a migration has the new build stand the older instances down before it migrates: each exits, App Service starts it again on the new image, and for about a minute nothing serves. Neither needs a step from you.
- A slot or a test instance never shares this database. From 1.32.0 a newer build started against
a production database stands every production instance down. Give a slot a database of its own, or
set
Database__MigrateOnStart=falseon it, which makes it refuse its own start instead. - An instance that cannot renew its registration for fifteen seconds is taken for dead by the
others, which end what it held. If it was only held up, it finds its registration gone, says so at
Criticaland registers again. See the next section for when that was seen.
What the first deployment met
Each of these happened on the deployment this guide was written from, with Server 1.32.0.
- Two instances starting together on an empty database both tried to create the first
Administrator. One created the roles and the account. The other logged, at
Error, "The admin account bootstrap did not complete" withDuplicateRoleName. The database ended complete, and the account signed in. If you see that line on a first start, look for "Created the first admin account" in the other instance's log before you worry. - As App Service replaced the containers on a settings change, one new instance's database
connection stalled for about 35 seconds. It renewed nothing for fifteen, the other instance took
it for dead, and it logged one
Criticalline and registered again. With no Workstation connected nothing was lost; on a deployment in use its machines would have reconnected. az sql db createandaz redisenterprise createeach needed the care steps 2 and 5 describe.