Azure Web Slots

2021年2月15日
Register here: http://gg.gg/oblnf
Every App Service resource in Azure has the ability to have multiple deployment slots configure. These deployments slots are a feature than can greatly help with the implementation of streamlined testing, staging, and deployment process. Along with the ability to configure multiple hosting environments, the use of Deployment Slots enables zero downtime when deploying application changes, or even rolling back a failed deployment.
In the Azure Portal, open the blade of your Azure App Service. Click Settings, and then click Deployment slots. In the “deployment slots” blade click on Add Slot. In the “Add a slot” blade, give the slot a name, and select whether to clone web app configuration from another existing deployment slot. Azure Deployment Slot is Awesome functionality for regular (Full) production deployment build process using Deployment Slot Swap functionality. Azure Web App Deployment Slots In order to configure Canary deployments, let’s go ahead and create a deployment slot. After the slot has been created, you will notice that the percentage of traffic which is going to the main slot is 100% while it is set to 0% on the slot which we just created.Creating Deployment Slots
Deployment slots or Azure slots are actually instances of Azure Web Apps which are tied to that website. A deployment slot will carry the name of the Azure Web App + SlotName. This template provides an easy way to deploy a web app with custom deployment slots on Azure Web Apps. This Azure Resource Manager (ARM) template was created by a member of the community and not by Microsoft.
Deployment slots are a feature of Azure App Service Plans. As a result, every App Service resource (Web App, Web API, Mobile App) in Microsoft Azure has the ability to create up to 4 additional deployment slots with the Standard tiers, and up to 20 deployment slots with the Premium tiers.
Each App Service (in Standard tiers) can have up to 4 additional Deployment Slots in addition to the Production slot.
Each Deployment Slot allows for a separate instance of the application to be hosted in isolation from the other deployment slots and production slot of the App Service. The VM behind each Deployment Slot is the same VM Instance that hosts the production deployment slot. This means that the App Service and 4 additional Deployment Slots will all be hosted in and share the same VM Instance and resources.
To create App Service Deployment Slots in the Azure Portal, just navigate to the App Service, select the Deployment slots section and click the Add Slot button to create a new Deployment Slot.
Additionally, in order to use the Deployment Slots feature of Azure App Service, the pricing tier must be either Standard or Premium. The Free, Shared, and Basic pricing tiers do not support deployment slots.
It’s important to keep in mind that all Deployment Slots share the same VM Instance and server resources.Deployment Slot URL / Endpoint
Azure App Service applications get a unique URL that is made up of the App Service Name as the subdomain of the azurewebsites.net domain. In the above screen shot, the App Service Name is “testapp2063” which means the URL / endpoint for the Production slot of the App Service is located at testapp2063.azurewebsites.net.
When creating Deployment Slots each slot gets it’s own URL / Endpoint. The endpoint for each deployment slot derives from the endpoint for the Production slot by appending the name of the deployment slot with a hyphen.
With an App Service named “testapp2063” the URL / Endpoint for the following deployment slots will have the following values:
*dev => testapp2063-dev.azurewebsites.net
*test => testapp2063-test.azurewebsites.net
*stage => testapp2063-stage.azurewebsites.netDeployment Slot Swapping
Swapping Deployment Slots is the method of copying the currently deployed application code and settings of one deployment slot and swapping it with another. Swapping allows for the deployment of application code to be done from one environment to another very quickly. It also allows for a couple new deployment techniques that didn’t exist in traditional server hosting.
To swap Deployment Slots from the Azure Portal, just navigate to the list of Deployment Slots for an App Service or navigate to the specific Deployment Slot that needs to be swapped. Then, click the Swap button and specify which Deployment Slot to swap with. See the above screenshots for reference of where the Swap button is located within the Azure Portal.
When an application is deployed using Deployment Slot swapping, there is zero downtime
When an application is deployed using Deployment Slot swapping, there is zero downtime of the application. The way this is implemented is by just rerouting the Deployment Slot Endpoint between the Deployment Slots being swapped. Both deployment slots remain running and actively responding to client requests throughout the swap.Staged Deployment
The technique of performing a Staged Deployment allows for application code to be deployed to a non-production deployment slot (such as one named stage) to test or verify functionality is working as expected. Then once everything has been verified, the Stage deployment slot can be swapped with Production making the staged application deployment the new Production instance of the application.Incremental Deployment
There are times when deploying application changes might require additional changes other than just deploying the latest code. These requirements could be running SQL scripts or some other post deployment step necessary to fully deploy the latest code. Deploying to a Stage deployment slot can allow for these Incremental steps to be performed after the code is deployed in a way that can be tested and verified before deploying to production.Rollback Deployment
Every once in awhile a deployment fails for some reason. Maybe files end up corrupt, a major bug is found, or some other reason for failure. In these cases, it’s necessary to rollback a deployment. Using Deployment Slots, a deployment can be rolled back easily buy just swapping the Deployment Slots back.
Basically, swap Stage with Production to deploy new changes. When a major bug is found that requires a rollback, then the Production and Stage Deployment Slots can be swapped back. This allows for the old application code to be rolled back into Production in a matter of minutes. This leads to greatly decreased downtime in the event of a deployment failure.
Chris is the Founder of Build5Nines.com and a Microsoft MVP in Azure & IoT with 20 years of experience designing and building Cloud & Enterprise systems. He is also a Microsoft Certified: Azure Solutions Architect, developer, Microsoft Certified Trainer (MCT), and Cloud Advocate. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive. Sponsored By
I’ve got a lot of production web sites running in Azure right now. Some are for small side projects and some are larger like the sites for the Hanselminutes Podcast and This Developer’s Life. I like Web Apps/Sites (which is Platform as a Service) rather than Virtual Machines (Infrastructure as a Service) because I don’t like thinking about the underlying operating system if I can avoid it. I like to be able to scale the site up (faster, bigger) or out (more machines in the farm) with a slider bar.
In fact, there’s some other more advanced and useful features that Azure Web Apps have that keep me using Web Apps almost exclusively.
I’ll use a little site I made called KeysLeft.com that tells you how many keystrokes are left in your hands before you die. Think of it as a productivity awareness tool.Azure Function App Slots
First, I’ll add a Deployment Slot to my existing Git-deployed Web App. The source for KeysLeft lives in GitHub here. When I check-in a change it’s automatically deployed. But what if I wanted to have a staging branch and automatically deploy to a staging.keysleft.com first? If it works out, then move it to production by swapping sites. That’d be sweet.Staging Slots for Azure Web Apps
You can see here my main KeysLeft web app has a Staging ’side car’ app that is totally separate but logically related/adjacent to production. Notice the ’swap’ button in the toolbar. Love it.
This Web App has its configuration copied from the main one, and I can setup Continuous Deployment to pull from a different branch, like ’staging’ for example. The name of the deployment slot becomes a suffix, so keysleft-staging.azurewebsites.net unless you set up a custom CNAME like staging.keysleft.com. You can have up to 4 deployment slots in addition to production (so dev, test, staging, whatever, production) on Standard Web Apps.A/B Testing for Azure Web Apps
Once I’ve got a slot or two set up and running a version of my app, I can do A/B testing if I’d like. I can set up a feature that was called ’Testing in Production’ and is now ’Traffic Routing’ and tell Azure what percentage of traffic goes to prod and what goes to staging. Of course, you have to be sure to write your application so such that authentication and session is managed however is appropriate, especially if you’d like the user to have a seamless experience.
Here I’ve got 10% of the traffic going to staging, seamlessly, and the other 90% is going to production. I can make a small change (background color for example) and then hit the main site over and over and see the occasional (10% of course) request being routed to the staging slot. You can configure this static routing however you’d like.
Then I could hook up Application Insights or New Relic or some other event/diagnostics system and measure the difference in user reaction between features that changed.Azure Web App Deployment Slots TrafficAdvanced Testing in Production
Made it this far? Then you’re in for a treat. Static routing is cool, to be clear, but scripting a more dynamic experience is even more interesting. Galin Iliev, one of the developers of this feature, gave me this Powershell script to show off more powerful stuff.
First, you can use PowerShell to manage this stuff. You can change routing values and ramp up or ramp down. For example, here we start at 10% and change it by 5 every 10 minutes. Azure Function Deployment Slot
But! What if you could write code to actually make the decision to continue or fall back dynamically? You can add a callback URL and a Site Extension called the ’TiP Callback Extension.’
The Site Extension (and all Site Extensions for that matter) is just a little sidecar Web API. This callback gets a small POST when it’s time to make a decision, and you decide what to do based on HTTP-related context that was passed in and then return a ChangeDirectionResult object as JSON. You can adjust traffic dynamically, you can adjust traffic when doing a deployment, do a slow, measured roll out, or back off if you detect issues.
NOTE: The ChangeDescisionCallbackUrl and this code below is totally optional (so don’t stress) but it’s super powerful. You can just do static routing, you can do basic scripted dynamic traffic routing, or you can have make a decision callback URL. So the choice is yours.
You can check out the code by visiting yoursite.scm.azurewebsites.net after installing the TiP callback site extension and look at the Site Extensions folder. That said, here is the general idea.
Here’s the object you return. It’s just a class with two ints, but this is super-annotated.
All this stuff is included in Standard Azure Web Apps so if you’re using Standard apps (I have 19 websites running in my one Standard plan) then you already have this feature and it’s included in the price. Pretty cool.Azure App Service SlotRelated Links
*Video: Intro to Testing in Production
*Video: Scripting Testing in Production and Traffic Routing
*Video: Azure WebSites - Deployment Slots for Staging Sites
Sponsor: Big thanks to Infragistics for sponsoring the feed this week. Responsive web design on any browser, any platform and any device with Infragistics jQuery/HTML5 Controls. Get super-charged performance with the world’s fastest HTML5 Grid - Download for free now!About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.AboutNewsletter
Register here: http://gg.gg/oblnf

https://diarynote.indered.space

コメント

最新の日記 一覧

<<  2025年7月  >>
293012345
6789101112
13141516171819
20212223242526
272829303112

お気に入り日記の更新

テーマ別日記一覧

まだテーマがありません

この日記について

日記内を検索