Understanding and Setting Up the Azure Resources to Deploy a Containerized Web App

Here, I’ll share a high-level explanation of the Azure resources our project team created to deploy a containerized web application. I will mention the prerequisite services required (that we created manually in the Azure Portal or Azure CLI). I’ll also share an example of how we set up our App Service as Terraformed infrastructure.

Resource Groups

We use different Azure Resource Groups for each environment. We also use a shared resource group for common services, such as the container registry or networking services.

So, if you are deploying to, say, a development, integration, and production environment, then you would have a total of four resource groups.

Container Registry

In the deployment pipeline, after testing and building the production app web, we tag the production image and push it to the Azure Container Registry. Then, later in the deployment process, we can set the App Service container settings. We’ll configure it to pull the tagged image from our container registry.

Since we will want to pull the same production image for each different environment, we manually created this container registry in our shared resource group:


az acr create --resource-group My-Shared-Resources --name MyContainerRegistry

App Service

We use Azure App Service to host the web app. We need to create three resources in each environment’s resource group for this:

  • App Service Plan – where we can configure the compute settings, such as operating system or region
  • App Service – where we can set app configurations, such as framework versions or health check endpoints
  • App Service Slot – an additional staging deployment slot, allowing us to validate the deployment before swapping it to the production slot

We set up App Service with Terraform.

Specifying your targeting environment:

# variables.tf
variable "environment" {
  description = "Name of the environment (e.g. dev, int, prod)"
  default     = "dev"
}

variable "target_rg" {
  description = "Target resource group where application resources are being deployed to"
  default     = "My_RG"
}

Creating the App Service resources:

# main.tf
data "azurerm_resource_group" "app_target_rg" {
  name = var.target_rg
}

resource "azurerm_app_service_plan" "my_app_service_plan" {
  name                = "my-app-service-plan-${var.environment}"
  location            = data.azurerm_resource_group.app_target_rg.location
  resource_group_name = data.azurerm_resource_group.app_target_rg.name
  kind                = "Linux"
  reserved            = true

  sku {
    tier = "Standard"
    size = "S1"
  }
}

resource "azurerm_app_service" "my_app_service" {
  name                = "etn-em-support-tool-app-service-${var.environment}"
  location            = data.azurerm_resource_group.app_target_rg.location
  resource_group_name = data.azurerm_resource_group.app_target_rg.name
  app_service_plan_id = azurerm_app_service_plan.my_app_service_plan.id
  https_only          = true

  site_config {
    always_on         = "true"
    health_check_path = "/health"
  }
}

resource "azurerm_app_service_slot" "my_staging_slot" {
  name                = "staging"
  app_service_name    = azurerm_app_service.my_app_service.name
  location            = data.azurerm_resource_group.app_target_rg.location
  resource_group_name = data.azurerm_resource_group.app_target_rg.name
  app_service_plan_id = azurerm_app_service_plan.my_app_service_plan.id
  https_only          = true

  site_config {
    always_on         = "true"
    health_check_path = "/api/health"
  }
}

Using Azure Resources to Deploy a Containerized Web App

There are many more options for configuring App Service, not to mention additional resources you’ll need to create to support, monitor, and protect your web app. However, I hope this high-level overview helps explain some of the different components required to deploy a web app with Azure.

Conversation

Join the conversation

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