Azure Cloud Service Deployment Slots

Azure App Services is extremely useful for developers. It offers Web Apps, API Apps, Mobile Apps and Function Apps (that run Azure Functions). All of these apps are incredibly powerful and can literally get you up and running in minutes. They provide a host of amazing features that you can leverage, like (auto)scaling, easy authentication, offline sync (for Mobile Apps), hybrid connections and many, many more. One feature that all of these apps share, is probably the most underrated one that many people don’t know about: deployment slots.

What Are Deployment Slots?

Develop, package, and deploy powerful applications and services to the cloud with Azure Cloud Services, and the click of a button. Scale from 1 to 1000 in minutes. Once your application is deployed, that’s it—from provisioning and load balancing, to health monitoring, Azure handles the rest. Azure App Services and Cloud Services are the two most popular, and easiest, ways to deploy your applications. They both support web applications and background service type applications. In this article, we will provide a comparison of Azure App services versus Cloud Services, along with a quick overview of each.

Deployment slots are incredible! They are the reason for many people to start using Azure App Services, like Web Apps. Let me explain why:
Suppose that you have a Web App. You run your website in it and it has an URL like production.website.com. In Azure App Services, you can very easily add a deployment slot. This is actually a full-fledged App Service, in this case a Web App, that sits next to you original Web App. The deployment slot has a different URL, maybe something like staging.website.com. Users use your website that is in the original Web App, because that is your production environment. You can deploy a new version of the website in the deployment slot, just so that you can test it before it goes live.
You could also do that in another Web App. But here is the magic of deployment slots: You can now Swap the deployment slot with production. When you do this, users will notice almost nothing and experience no downtime. The swap functionality of the deployment slot takes care of this magic. Isn’t that awesome?

Deployment Slot Facts

Before I tell you even more things that make deployment slots awesome, let me state out the facts about deployment slots:

  • A deployment slot is a full-fledged App Service that lives within the same App Service Plan as your original App Service
    • This means that deployment slots use some of the resources in the App Service Plan, which could influence the performance of your main App Service
  • The original App Service is also called the production slot
  • Deployment slots can copy the configuration (AppSettings and Connectionstrings) of the original App Service or other deployment slots
  • Your App Service needs to (at least) be in the Standard Pricing tier
  • You can create 4 deployment slots next to your original App Service in the Standard Pricing tier
  • And you can create 19 deployment slots next to your original App Service in the Premium Pricing tier
  • When you scale a deployment slot (up or out), you also scale all the other slots of the App Service. This is because all slots share the same App Service Plan
  • If you have installed any site extensions, you need to do that again in a deployment slot as it is a new App Service instance
  • Deployment slots have a different URL then the original App Service. This URL is based on the name you give the deployment slot, for instance “staging” can become http://website-staging.azurewebsites.net

Alright, let’s take a look at how to setup deployment slots and what the major benefits are in more detail.

Azure Cloud Service Deployment Slots

Setting up Deployment Slots

Creating a deployment slot is very easy and, as always, there are many ways to do it. You can use the Azure Portal, Azure CLI, Azure PowerShell and the Azure Management API. I’ll show you how to do it using the Azure Portal.
In the Azure Portal, navigate to your App Service - let’s say it’s a Web App - and click the deployment slots menu item:
Now you see the Add Slot button, which opens the Add Slot dialog, to the right of the screen. Here, you need to enter a name, and choose if you want to copy the configuration from another slot, or not at all. Click OK and voila, you have a deployment slot!

Choosing to copy the configuration is important, because your app probably does things like connect to a database or cache and has specific connectionstrings in these settings.

Visit my Pluralsight course for a full video tutorial about setting up and using deployment slots.

Deploying your app to deployment slots

When you have created a deployment slot, it is empty, just like when you create a new App Service. You need to deploy a version of your app to the deployment slot before you can use it.
You can use the same tools and techniques that you use to deploy your app to the App Service: through Visual Studio, using something like VSTS (Visual Studio Team Services) or Octopus Deploy, using Web Deploy or any number of other technologies. Selecting a deployment slot to deploy to from Visual Studio looks like this:

Swap and Rollback

One of the major benefits of deployment slots is that you can swap them. What does that mean?

Swapping
Azure cloud service deployment slots download

Suppose that I have a website deployed in a Web App. This Web App has the custom URL https://www.azure-overview.com/. I have created a new version of the website and want to test it before publishing it. So I create a deployment slot called staging, which has the URL http://azureoverview-staging.azurewebsites.net. I’ve made sure that the slot has the same configuration values so that I use the same database and cache as production does. I’ve deployed the new website in the deployment slot and I’m happy with my changes and want to deploy to production. I can do this by performing a swap:
I can do this from the Azure Portal, Azure CLI, Azure PowerShell and the Azure Management API. In the Azure Portal, I can choose what the source and destination slots are and click OK. This will swap the slots and will deploy my changes to production. Here’s the thing: Users will experience no downtime!

And that’s because a swap does the following:

  • The source slot will be warmed-up. Azure does this by firing a couple requests into the root of the slot. You can also configure custom warm-up rules
  • Swaps the Virtual IP addresses of the source and destination slots, thereby swapping the URLs of the slots
  • It also applies (or keeps, depending on how you see it) certain settings that are specific to the target slot:
    • Publishing endpoints
    • Custom Domain Names
    • SSL certificates and bindings
    • Scale settings
    • WebJobs schedulers

This results in a seamless transition to production. Users experience virtually no downtime. I say virtually because users that are in the midst of doing something that depends on state that is in-memory of the Web App, will lose this state. But you shouldn’t keep state locally in an App Service anyways in Azure as you should assume that everything in Azure is volatile.

Rollback

After a swap, the “old” website will be in the staging slot and the “new” website in the production slot.
If you aren’t happy with the version in production, you can easily rollback your deployment. Simply swap back to reverse the effect!

Swapping options

You can swap manually, but you have more options:

Auto Swap

Cloud

You can choose to swap automatically to a slot when there is a new version of your app in a deployment slot – this is called Auto Swap. Simply enable it in the Application Settings of the deployment slot:

Swap with preview

You can choose to swap with preview when you perform a swap from the Azure Portal. This does the following:

  • It performs the swap in stages
  • It applies the configuration elements of the destination slot to the source slot, so that you can test if everything works as expected, before the actual swap happens
  • (if you complete the swap), it does the same as in a manual swap, warm-up the slot and perform the swap
Swap and VSTS

If you use something like VSTS (Visual Studio Team Services), you can also leverage deployment slots and the swap feature. You can deploy a new version of your app to a deployment slot and then swap it using steps in a release definition. The illustration below shows this for a release definition in VSTS:

Testing in Production

Besides swapping, deployment slots offer another killer feature: testing in production. Just like the name suggests, using this, you can actually test in production. This means that you can route a specific percentage of user traffic to one or more of your deployment slots:
With testing in production, you can have some users use the new version of your application. This way, you can see if and how they use new features. In order to find this out, you need to make sure that you monitor everything, with something like Stackify Retrace.

Setup

Testing in production is easy to setup. In the Azure Portal, choose the testing in production menu option in your App Service.
Here, you can choose the deployment slots that you want to route traffic to (or add new ones) and assign a percentage of traffic to them. That’s it! Now users will be routed to your deployment slots – super powerful!

Conclusion

Azure Cloud Service Deployment Slots Download

Deployment slots are awesome and I hope that you give them a chance. You can use them for all sorts of things, but there are also things to keep in mind. Here is the quick overview:

Pros:

  • Using the **swap **feature gives you zero-downtime deployments
  • You can test the new version of your app using the testing in production feature
  • Deployment slots are great to verify a new version of an app before it goes live

Cons:

  • A deployment slot is a full-fledged App Service that lives within the same App Service Plan as your original App Service, which might impact the performance of your original App Service
  • A deployment slot is a new App Service. This means that you have to reinstall any site extensions that you have installed in you App Service
  • Your App Service needs to (at least) be in the Standard Pricing tier
  • You can’t scale a deployment slot, separate from other deployment slots in the App Service. This makes a deployment slot not suitable for performance testing – you should use a separate App Service for that

Start using deployment slots and use them wisely! Let me know what you think in the comments.

-->

Summary

Azure Cloud Service Deployment Slots Online

When you deploy instances to a Cloud Service or add new web or worker role instances, Microsoft Azure allocates compute resources. You may occasionally receive errors when performing these operations even before you reach the Azure subscription limits. This article explains the causes of some of the common allocation failures and suggests possible remediation. The information may also be useful when you plan the deployment of your services.

Azure Cloud Service Deployment Slots Software

If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and Stack Overflow. You can post your issue in these forums, or post to @AzureSupport on Twitter. You also can submit an Azure support request. To submit a support request, on the Azure support page, select Get support.

Background – How allocation works

The servers in Azure datacenters are partitioned into clusters. A new cloud service allocation request is attempted in multiple clusters. When the first instance is deployed to a cloud service(in either staging or production), that cloud service gets pinned to a cluster. Any further deployments for the cloud service will happen in the same cluster. In this article, we'll refer to this as 'pinned to a cluster'. Diagram 1 below illustrates the case of a normal allocation which is attempted in multiple clusters; Diagram 2 illustrates the case of an allocation that's pinned to Cluster 2 because that's where the existing Cloud Service CS_1 is hosted.

Why allocation failure happens

When an allocation request is pinned to a cluster, there's a higher chance of failing to find free resources since the available resource pool is limited to a cluster. Furthermore, if your allocation request is pinned to a cluster but the type of resource you requested is not supported by that cluster, your request will fail even if the cluster has free resource. Diagram 3 below illustrates the case where a pinned allocation fails because the only candidate cluster does not have free resources. Diagram 4 illustrates the case where a pinned allocation fails because the only candidate cluster does not support the requested VM size, even though the cluster has free resources.

Troubleshooting allocation failure for cloud services

Azure Cloud Service Deployment Slots Free

Error Message

You may see the following error message:

'Azure operation '{operation id}' failed with code Compute.ConstrainedAllocationFailed. Details: Allocation failed; unable to satisfy constraints in request. The requested new service deployment is bound to an Affinity Group, or it targets a Virtual Network, or there is an existing deployment under this hosted service. Any of these conditions constrains the new deployment to specific Azure resources. Please retry later or try reducing the VM size or number of role instances. Alternatively, if possible, remove the aforementioned constraints or try deploying to a different region.'

Common Issues

Here are the common allocation scenarios that cause an allocation request to be pinned to a single cluster.

  • Deploying to Staging Slot - If a cloud service has a deployment in either slot, then the entire cloud service is pinned to a specific cluster. This means that if a deployment already exists in the production slot, then a new staging deployment can only be allocated in the same cluster as the production slot. If the cluster is nearing capacity, the request may fail.
  • Scaling - Adding new instances to an existing cloud service must allocate in the same cluster. Small scaling requests can usually be allocated, but not always. If the cluster is nearing capacity, the request may fail.
  • Affinity Group - A new deployment to an empty cloud service can be allocated by the fabric in any cluster in that region, unless the cloud service is pinned to an affinity group. Deployments to the same affinity group will be attempted on the same cluster. If the cluster is nearing capacity, the request may fail.
  • Affinity Group vNet - Older Virtual Networks were tied to affinity groups instead of regions, and cloud services in these Virtual Networks would be pinned to the affinity group cluster. Deployments to this type of virtual network will be attempted on the pinned cluster. If the cluster is nearing capacity, the request may fail.

Solutions

  1. Redeploy to a new cloud service - This solution is likely to be most successful as it allows the platform to choose from all clusters in that region.

    • Deploy the workload to a new cloud service
    • Update the CNAME or A record to point traffic to the new cloud service
    • Once zero traffic is going to the old site, you can delete the old cloud service. This solution should incur zero downtime.
  2. Delete both production and staging slots - This solution will preserve your existing DNS name, but will cause downtime to your application.

    • Delete the production and staging slots of an existing cloud service so that the cloud service is empty, and then
    • Create a new deployment in the existing cloud service. This will re-attempt to allocation on all clusters in the region. Ensure the cloud service is not tied to an affinity group.
  3. Reserved IP - This solution will preserve your existing IP address, but will cause downtime to your application.

    • Create a ReservedIP for your existing deployment using Powershell

    • Follow #2 from above, making sure to specify the new ReservedIP in the service's CSCFG.

  4. Remove affinity group for new deployments - Affinity Groups are no longer recommended. Follow steps for #1 above to deploy a new cloud service. Ensure cloud service is not in an affinity group.

  5. Convert to a Regional Virtual Network - See How to migrate from Affinity Groups to a Regional Virtual Network (VNet).