Deploy Azure App Service with Zero Downtime
Zero downtime deployment is a way of deployment where application will never down during the deployment process. With this we can successfully introduce a new version of an application without any downtime. For an Azure app service that is possible with slots.
- Create App service with a standard or premium plan to add slots. (Free/ basic plan does not includes slots deployment)
Go to App service deployment > Deployment slots. Default slot name is production which will be in running status.
2. Add new slot name it as “staging”
3. Get code on repository and create build pipeline. I have very basic asp.net application and its code as shown on following screen :
4. On build pipeline we do not need any setting for specific slot we can just add all steps which are needed to build solution. And make sure build artifacts are ready to use.
5. Create new service connection : We will need it to connect from Azure Pipelines to remote app services for executing tasks in a job. Once you establish a connection, you can view, edit, and add security to the service connection.
6. Create release pipeline to deploy application on slot using Azure App Service deployment template.
To deploy application on slot check box “Deploy to Slot or App Service Environment” has to be true. Select the option to deploy to an existing deployment slot or Azure App Service Environment. For both the targets, the task needs Resource group name. In case the deployment target is a slot, by default the deployment is done to the production slot. Any other existing slot name can also be provided. We have already created slot named as “staging”.
With this release pipeline all changes will always get deployed to staging app. On stage app it is possible to validate all changes are working as expected and then changes can swap to production slot. As we can see changes are in staging but not in production.
7. Now its time to swap changes from staging to production. Open web app Overview > click on Swap, it opens a panel where we can select source and target application and then click Swap button on panel.
Swap is last step of zero downtime deployment which can be done automatically using the App Service (Slot) staging (blogdemoapp/staging) > Configuration > General Settings > Auto swap enabled (On) > Auto swap deployment (Production) > Save