Azure deployment slots are a powerful tool for managing the deployment of your Azure applications. They allow you to have multiple environments for testing and staging, which is essential for ensuring a smooth and successful deployment.
Having multiple deployment slots can save you a significant amount of time and effort. You can test and validate your application in a staging slot before promoting it to production.
Each deployment slot in Azure is a unique endpoint that can be accessed by users. This means you can have multiple versions of your application running at the same time, which is useful for A/B testing and canning new features.
Azure deployment slots are also highly scalable, allowing you to easily scale up or down as needed. This is especially useful for applications that experience sudden spikes in traffic.
Prerequisites
To deploy Azure deployment slots, you'll need to meet certain prerequisites.
You can access the Azure portal, which is a web-based interface for managing Azure resources, to perform slot operations.
To use the Azure CLI, you'll need to install it on your machine or use it through the Azure portal.
The Azure PowerShell is another tool that allows you to manage Azure resources, including deployment slots.
To get started, you'll need to search for the required permissions in the Resource provider operations.
Here's a quick rundown of the tools you'll need:
- Azure portal
- Azure CLI
- Azure PowerShell
Azure Services
Azure Services allow you to create a deployment slot called staging for testing new versions of your website before pushing them to production.
You can create a deployment slot with a custom URL address, such as https://www.azureslots.staging.azureservices.net.
Azure ensures that the staging slot has the same configuration values as the production slot, using the same database and cache values.
To deploy a new version to production, you can swap the source and destination slots by swapping their virtual IP addresses.
This process also updates certain settings specific to the target slot, such as publishing endpoints and custom domain names.
Setting up an app service with a sample web server is a great way to test changes and perform the swap.
App Service Creation
To create an app service slot, start by navigating to your Azure app service in the Azure portal. From there, click on the deployment slot in the left side panel and choose 'add slots' to create your staging environment.
Give your staging slot a name like "Staging" so it's easy to identify. You'll see a new app service slot in your resource group dedicated to hosting the code pushed from the repository.
To navigate to the deployment slot, follow these steps:
- Navigate to the deployment slot and click on the newly created staging slot
- Go to the deployment center for the staging slot and choose the repo location of your choice
Create a Plan
To create a plan for your App Service, start by defining your goals and requirements. This will help you determine the type of App Service you need and the resources required to support it.
You'll need to decide on the type of App Service, such as a Standard logic app or a deployment slot. In Azure portal, you can create a deployment slot by opening your Standard logic app resource and selecting Deployment slots (Preview) from the resource menu.
To create a deployment slot, you'll need to provide a unique name that uses only lowercase alphanumeric characters or hyphens. For example, if your logic app name is "mylogicapp" and your deployment slot name is "staging", the slot name will be "mylogicapp-staging".
In Visual Studio Code, you can also create a deployment slot by opening the command palette and selecting Azure Logic Apps: Create Slot. This will prompt you to provide the required information, including the logic app name, resource group name, and slot name.
Here are the steps to create a deployment slot:
- Open your Standard logic app resource in Azure portal
- Select Deployment slots (Preview) from the resource menu
- Click Add and provide a unique name for your deployment slot
- Select Add to create the deployment slot
Once you've created your deployment slot, you can confirm its creation by opening your deployed logic app resource in Azure portal and selecting Deployment slots (Preview) from the resource menu. Your new deployment slot should be listed on the Deployment Slots page.
Resource Manager Template
Azure Resource Manager templates are declarative JSON files used to automate the deployment and configuration of Azure resources. They are a powerful tool for managing your App Service creation process.
To use Resource Manager templates for swapping slots, you need to set two properties: buildVersion and targetBuildVersion. The buildVersion is a string property that represents the current version of the app deployed in the slot.
The targetBuildVersion is a string property that specifies what buildVersion the slot should have. If it doesn't equal the current buildVersion, it triggers the swap operation by finding the slot with the specified buildVersion.
Here are the properties you need to set on the Microsoft.Web/sites/slots and Microsoft.Web/sites resources:
- buildVersion: a string property representing the current version of the app deployed in the slot.
- targetBuildVersion: a string property specifying what buildVersion the slot should have.
These properties are used in the example Resource Manager template, which swaps two slots by updating the buildVersion of the staging slot and setting the targetBuildVersion on the production slot. The template is idempotent, meaning it can be executed repeatedly without triggering any slot swap if the slots are already in the desired state.
Deployment Steps
To deploy an Azure deployment slot, you'll need to create a new slot from your existing Azure App Service. This can be done by clicking on the "Slots" tab in the Azure portal and then clicking the "Add slot" button.
You can then choose the settings for your new slot, such as the instance size and the number of instances. For example, if you're creating a staging slot, you might want to choose a smaller instance size to save costs.
Once you've created your new slot, you can swap it with your production slot by clicking on the "Swap" button in the Azure portal. This will make the new slot the live version of your App Service, and the old production slot will become the staging slot.
Operation Steps
To add a deployment slot, you must enable multiple deployment slots in your Azure app, which requires it to be in the Standard, Premium, or Isolated tier.
You can clone a configuration from any existing slot, including app settings, connection strings, language framework versions, web sockets, HTTP version, and platform bitness.
To create a deployment slot, navigate to your Azure app service and click on the deployment slot in the left side panel, then choose 'add slots' to create your staging environment.
Give the slot a name, such as "Staging", to easily identify it.
To swap two slots, App Service applies the target slot's settings to the source slot, causing all instances to restart.
The swap operation pauses after the first phase, allowing you to validate that the source slot works correctly with the target slot's settings.
To swap a slot into production, run the following command in a terminal:
To swap a slot into production, run the following cmdlet in a PowerShell terminal:
Here are the swap operation steps in detail:
- Apply settings from the target slot to all instances of the source slot, causing all instances to restart.
- Wait for every instance in the source slot to complete its restart.
- Trigger local cache initialization on each instance of the source slot, if local cache is enabled.
- Wait until each instance returns any HTTP response.
- Swap the two slots by switching the routing rules for the two slots.
- Apply all settings and restart the instances in the source slot.
Deploy Logic App Changes
To deploy logic app changes, you'll need to use Visual Studio Code or the Azure CLI. In Visual Studio Code, open your Standard logic app project and select Azure Logic Apps: Deploy to Slot from the command palette.
You can also use the Azure CLI command `az logicapp deployment source config-zip` to deploy your changes. This command requires you to provide the logic app name, resource group name, slot name, and deployment package local path.
Deploying to a deployment slot will overwrite any existing content in the selected slot, so be sure to confirm that you want to deploy the current code in your project. To confirm deployment, check the Notifications tab on the Overview page of your deployed logic app resource.
After deployment, you can update any settings by selecting Upload settings in the message box that appears. To verify the changes in your workflow, select Workflows and then select a workflow, which appears in read-only view.
Here are the steps to deploy logic app changes in a deployment slot:
- In Visual Studio Code, open the Standard logic app project that you want to deploy.
- Open the command palette and select Azure Logic Apps: Deploy to Slot.
- Follow the prompts to provide the required information, including the logic app name, resource group name, slot name, and deployment package local path.
- Confirm that you want to deploy the current code in your project by selecting Deploy.
- Update any settings by selecting Upload settings in the message box that appears.
Next Steps
Now that you've completed the deployment steps, it's time to think about the next steps you should take.
First, review your deployment plan to ensure everything went smoothly. You should have a detailed plan in place that outlines all the steps involved in deploying your application.
Make any necessary adjustments to your plan to account for any issues that arose during deployment. This will help you avoid similar problems in the future.
Consider implementing a continuous integration and continuous deployment (CI/CD) pipeline to streamline your deployment process. This can help you automate many of the steps involved in deployment and reduce the risk of human error.
Regularly monitor your application's performance and make adjustments as needed to ensure it's running smoothly and efficiently. This will help you catch any issues before they become major problems.
Deployment Options
Azure deployment slots offer flexibility and control over your application's deployment process. You can have multiple slots, each with its own configuration and settings, allowing you to test and refine your application without affecting production.
You can swap between slots in a few clicks, making it easy to roll back to a previous version if something goes wrong. For example, if you're testing a new feature and it causes issues, you can quickly swap back to the previous slot.
There are three main deployment options: manual deployment, continuous deployment, and continuous integration and deployment. Manual deployment allows you to deploy your application manually, while continuous deployment and continuous integration and deployment automate the process for you.
Flexibility of Instances
With our flexible instance swapping, you can seamlessly redirect traffic to a new app instance without any downtime, ensuring a smooth experience for your users.
You can swap different app instances from source to target with no impact on performance, giving users the best experience anytime, anywhere.
Traffic redirection is handled with ease, so no requests are left out due to a swap.
Function execution remains uninterrupted during a swap, and subsequent triggers are automatically redirected to the swapped app instance.
Rollback Options
Rollback options are a game-changer for teams that need to quickly revert to a previous version of their app.
If your team is unhappy with the latest update, you can roll back your app to the previous version within the same app service. This eliminates downtime, allowing your users to continue enjoying uninterrupted service.
Rolling back is a seamless process that doesn't require a lot of technical expertise. You can do it quickly and easily, which is a huge time-saver for development teams.
Frequently Asked Questions
What are deployment slots in Azure?
Azure deployment slots are separate environments for your function app, each with its own instance and publicly accessible endpoint. You can easily swap instances between slots to test, stage, or deploy your app with minimal downtime.
How many additional deployment slots can you create in Azure?
You can create up to 20 additional deployment slots in Azure, aside from the production deployment slot. Learn more about Azure App Service plans and deployment slots.
What is the maximum deployment slot in Azure web app?
The maximum deployment slots in Azure web app vary by pricing tier, with Standard offering up to 5 slots and Premium offering up to 20. Learn more about deployment slots and pricing tiers to customize your deployment strategy.
Sources
- https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/
- https://henriquesd.medium.com/azure-app-services-deployment-slots-a962cc1d75b3
- https://learn.microsoft.com/en-us/azure/app-service/deploy-staging-slots
- https://learn.microsoft.com/en-us/azure/logic-apps/set-up-deployment-slots
- https://www.partech.nl/nl/publicaties/2021/06/understanding-deployment-slots-in-azure-app-services
Featured Images: pexels.com