Azure Container Apps – traffic splitting [part 4]

Azure Container Apps – traffic splitting, or having multiple revisions of your application and sharing traffic between them. You can specify the weight for each route, so the traffic load can be adjusted properly. The total of all weights must be 100. In my configuration, I assign a revision suffix to each deployment. You may view all of the series’ articles here.

Azure Container Apps – traffic splitting – Terraform setup

Before we go into the Terraform setup, you can download all of the sources here. If you’re not sure how to configure Azure Container Apps with Terraform, please see my prior post: Azure Container Apps – Using Terraform to Create [Part 1]

In this section, I simply identify differences from the basic Azure Container Apps configuration. To begin, set the revision mode to Multiple in order to determine traffic splitting:

Azure Container Apps – traffic splitting

When revision mode is defined, the next step is to set the revision name. In Terraform we must assign value to the revion_suffix field. However, keep in mind that this value must be unique. You will receive an error if you attempt to deploy an existing revision name.

Azure Container Apps – traffic splitting

We can define our traffic weights based on the revision suffix. I used a dynamic block to accomplish this.

Azure Container Apps – traffic splitting

I’m using the traffic_weights variable, as you can see. The variable’s definition is as follows:

Azure Container Apps – traffic splitting

You must execute the following commands to launch my sample:

terraform init
terraform apply -var-file=release_1.tfvars 
terraform apply -var-file=release_2.tfvars  

In the first apply, the initial revision is created. Then running the second, adding the next revision, and configuring traffic splitting. In release_2.tfvars, you will find the weight specification for the reach revision:

traffic_weights = [
  {
    revision_suffix = "r22",
    percentage      = 70
  },
  {
    revision_suffix = "r1",
    percentage      = 30
  }
]

I sincerely hope you enjoyed it, and if so, I’d appreciate a Like or Comment on my LinkedIn profile.

Here you can find all the articles from the series.

Leave a Reply

Your email address will not be published. Required fields are marked *