Azure App Service Deployment Slots

Learn how to use deployment slots to manage your application deployments more effectively.

Introduction

Azure App Service deployment slots allow you to deploy multiple versions of your application to the same App Service instance. This is a powerful feature for implementing blue-green deployments, canary releases, and A/B testing, minimizing downtime and risk during updates.

What are Deployment Slots?

A deployment slot is essentially a live application instance within your App Service. When you create an App Service, it comes with a default production slot. You can then create additional slots (e.g., staging, development, testing) to host different versions of your application. Each slot has its own deployment history and can be configured independently.

Each deployment slot has its own hostname, allowing you to access and test it separately before promoting it to production.

Benefits of Using Deployment Slots

  • Zero Downtime Deployments: Swap slots to redirect traffic seamlessly.
  • Safe Rollbacks: Easily swap back to a previous version if an issue arises.
  • Testing and Staging: Test new releases in a production-like environment before going live.
  • Blue-Green Deployments: Maintain two identical environments and switch traffic between them.
  • Canary Releases: Gradually roll out new versions to a subset of users.

Creating Deployment Slots

You can create new deployment slots through the Azure portal, Azure CLI, or Azure PowerShell.

Using the Azure Portal:

  1. Navigate to your App Service in the Azure portal.
  2. In the left-hand menu, under "Deployment," select "Deployment slots."
  3. Click "+ Add Slot."
  4. Provide a name for the new slot (e.g., "staging").
  5. Optionally, choose to clone configurations from an existing slot.
  6. Click "Add."

Using Azure CLI:


az webapp deployment slot create --name <your-app-name> --resource-group <your-resource-group> --slot <slot-name>
                

Managing Deployment Slots

Once created, you can manage your slots from the "Deployment slots" section in the Azure portal. Here you can:

  • View the URL for each slot.
  • Deploy new versions to a specific slot.
  • Configure settings for each slot.
  • Swap slots.
  • Delete slots.
Remember to configure your CI/CD pipeline to deploy to the appropriate slot.

Swapping Slots

The "Swap" operation is the core of using deployment slots effectively. It allows you to exchange the content and configurations of two slots. This is a zero-downtime operation.

Swap Process:

  1. Select the slot you want to swap from (e.g., "staging").
  2. Click the "Swap" button.
  3. Choose the target slot (usually "production").
  4. Azure performs a "warm-up" of the target slot's content.
  5. Traffic is then redirected to the new production slot.
  6. The original production slot now contains the content that was previously in the staging slot.

This process can be automated within your CI/CD pipeline.

Consider using --action swap with az webapp deployment slot swap for programmatic control.

Configuration Settings

Each deployment slot can have its own application settings, connection strings, and general settings. This is crucial for managing different environments.

Slot-Specific Settings:

Some settings, like connection strings, are often environment-specific. You can mark these as "deployment slot settings." When you swap slots, these settings remain in their original slots, ensuring that the correct configurations are applied to the correct environments.

To mark a setting as a slot setting:

  1. Go to the App Service's "Configuration" blade.
  2. Find the setting you want to be slot-specific.
  3. Check the "Deployment slot setting" box next to it.
  4. Save the changes.

Advanced Usage

Deployment slots can be integrated with various Azure services and deployment strategies:

  • CI/CD Pipelines: Automate deployments to specific slots using Azure DevOps, GitHub Actions, etc.
  • Traffic Routing: Use Azure Front Door or Application Gateway for more granular traffic management and advanced routing rules.
  • A/B Testing: Deploy different features to separate slots and route traffic to them based on user percentages.
graph TD A[Source Control] --> B(CI/CD Pipeline); B --> C{Deploy to Staging Slot}; C --> D[Test Staging Slot]; D --> E{Swap Staging & Production}; E --> F[Production Slot Live]; E --> G[Staging Slot Receives Old Prod Content];

This diagram illustrates a typical blue-green deployment workflow using staging and production slots.