The experience of blue-green deployment in Azure Container Apps

Note

The Basic, Standard, and Enterprise plans will be deprecated starting from mid-March, 2025, with a 3 year retirement period. We recommend transitioning to Azure Container Apps. For more information, see the Azure Spring Apps retirement announcement.

The Standard consumption and dedicated plan will be deprecated starting September 30, 2024, with a complete shutdown after six months. We recommend transitioning to Azure Container Apps. For more information, see Migrate Azure Spring Apps Standard consumption and dedicated plan to Azure Container Apps.

This article applies to: ✅ Basic/Standard ✅ Enterprise

This article describes blue-green deployment with Azure Container Apps.

In Azure Container Apps, you can enable blue-green deployment by combining container apps revisions, traffic weights, and revision labels.

Create or update a container app with multiple active revisions enabled

To create a new container app with multiple active revisions enabled, use the following command:

az containerapp create \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --environment <APP_ENVIRONMENT_NAME> \
    --image mcr.microsoft.com/k8se/samples/test-app:<BLUE_COMMIT_ID> \
    --revision-suffix <BLUE_SUFFIX> \
    --ingress external \
    --target-port 80 \
    --revisions-mode multiple

Alternatively, you can use the following command to update an existing app to enable multiple revisions:

az containerapp revision set-mode \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --mode multiple

Deploy a new revision and assign labels

To deploy a new revision, use the following command:

az containerapp update \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --image mcr.microsoft.com/k8se/samples/test-app:<GREEN_COMMIT_ID> \
    --revision-suffix <GREEN_SUFFIX>

You can add labels to specific revisions as shown in the following example:

az containerapp revision label add \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --label blue \
    --revision <APP_NAME>--<BLUE_SUFFIX>

az containerapp revision label add \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --label green \
    --revision <APP_NAME>--<GREEN_SUFFIX>

Initially, the revision with the blue commitId takes 100% of production traffic, while the newly deployed revision with the green commitId doesn't take any production traffic.

In Azure Spring Apps, you can deploy at most two revisions of one app: one set as Production and the other as Staging. However, Azure Container Apps supports deploying multiple revisions for a single app.

Test a new revision

Each revision in Azure Container Apps has its own URL, enabling you to test and verify your deployment against the specific URL. Use the following commands to test the green revision with a specific domain, even though all production traffic is directed to the blue revision:

export GREEN_DOMAIN=$(az containerapp revision show \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --revision <GREEN_REVISION_NAME> \
    --query "properties.fqdn" \
    --output tsv \
    | tr -d '\r\n')

curl -s http://$GREEN_DOMAIN

Use the following commands to test with the label-specific fully qualified domain name (FQDN):

# Get the containerapp environment default domain
export APP_DOMAIN=$(az containerapp env show \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_ENVIRONMENT_NAME> \
    --query "properties.defaultDomain" \
    --output tsv \
    | tr -d '\r\n')

# Test the production FQDN
curl -s https://$APP_NAME.$APP_DOMAIN

# Test the blue label FQDN
curl -s https://$APP_NAME---blue.$APP_DOMAIN

# Test the green label FQDN
curl -s https://$APP_NAME---green.$APP_DOMAIN

Send production traffic to the green revision

To switch production traffic to the green revision, use the following commands:

# switch based on revision name
az containerapp ingress traffic set \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --revision-weight <BLUE_REVISION_NAME>=0 <GREEN_REVISION_NAME>=100

# switch based on label
az containerapp ingress traffic set \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --label-weight blue=0 green=100

Ensure that the total label weight doesn't exceed 100.

Azure Container Apps not only enables you to switch traffic between blue-green deployments but also between multiple revisions. You can also redirect a specific amount of production traffic to the green deployment.

For more information about blue-green deployment in Azure Container Apps, see Blue-Green Deployment in Azure Container Apps.

Limitation

The Eureka Server isn't suitable for blue-green deployment because all revisions of the app are registered with the Eureka Server, preventing effective traffic splitting.

To enable traffic splitting when using Spring Cloud Gateway, you need to set the application URL in the URI field of your gateway configuration. You can obtain the application URL by using the following command:

az containerapp show \
    --resource-group <RESOURCE_GROUP> \
    --name <APP_NAME> \
    --query "properties.configuration.ingress.fqdn" \
    --output tsv \
    | tr -d '\r\n'