Skip to content

Latest commit

 

History

History
263 lines (175 loc) · 8.71 KB

prod-deployment.md

File metadata and controls

263 lines (175 loc) · 8.71 KB

Steps to deploy the production deployment

This section describes the deployment steps for the reference implementation of a reliable web application pattern with .NET on Microsoft Azure. These steps guide you through using the jump box that is deployed when performing a network isolated deployment because access to resources will be restricted from public network access and must be performed from a machine connected to the vnet.

Diagram showing the network focused architecture of the reference implementation.

Prerequisites

We recommend that you use a Dev Container to deploy this application. The requirements are as follows:

If you do not wish to use a Dev Container, please refer to the prerequisites for detailed information on how to set up your development system to build, run, and deploy the application.

Note

These steps are used to connect to a Linux jump box where you can deploy the code. The jump box is not designed to be a build server. You should use a devOps pipeline to manage build agents and deploy code into the environment. Also note that for this content the jump box is a Linux VM. This can be swapped with a Windows VM based on your organization's requirements.

Steps to deploy the reference implementation

The following detailed deployment steps assume you are using a Dev Container inside Visual Studio Code.

1. Log in to Azure

  1. Start a powershell session in the dev container terminal:

    pwsh
  2. Import the Azure cmdlets:

    Import-Module Az.Resources
  3. Log in to Azure:

    Connect-AzAccount -UseDeviceAuthentication
  4. Set the subscription to the one you want to use (you can use Get-AzSubscription to list available subscriptions):

    $AZURE_SUBSCRIPTION_ID="<your-subscription-id>"
    Set-AzContext -SubscriptionId $AZURE_SUBSCRIPTION_ID
  5. Azure Developer CLI (azd) has its own authentication context. Run the following command to authenticate to Azure:

    azd auth login --use-device-code

2. Provision the app

  1. Create a new AZD environment to store your deployment configuration values:

    azd env new <pick_a_name>
  2. Set the default subscription for the azd context:

    azd env set AZURE_SUBSCRIPTION_ID $AZURE_SUBSCRIPTION_ID
  3. To create the prod deployment:

    azd env set ENVIRONMENT prod
  4. Production is a multi-region deployment. Choose an Azure region for the primary deployment (Run (Get-AzLocation).Location to see a list of locations):

    azd env set AZURE_LOCATION <pick_a_region>

    You want to make sure the region has availability zones. Azure App Service is configured with Availability zone support.

  5. Choose an Azure region for the secondary deployment:

    azd env set AZURE_SECONDARY_LOCATION <pick_a_region>

    We encourage readers to choose paired regions for multi-regional web apps. Paired regions typically offer low network latency, data residency in the same geography, and sequential updating. Read Azure paired regions to learn more about these regions.

  6. Run the following command to create the Azure resources (about 45-minutes to provision):

    azd provision

3. Upload the code to the jump box

  1. Start a new PowerShell session in the terminal (In VS Code use Ctrl+Shift+~). Run the following command from the dev container terminal to start a new PowerShell session:

    pwsh
    
  2. We use the Azure CLI to create a bastion tunnel that allows us to connect to the jump box:

    az login --use-device-code
    $AZURE_SUBSCRIPTION_ID = ((azd env get-values --output json | ConvertFrom-Json).AZURE_SUBSCRIPTION_ID)
    az account set --subscription $AZURE_SUBSCRIPTION_ID
  3. Run the following to set the environment variables for the bastion tunnel:

    $bastionName = ((azd env get-values --output json | ConvertFrom-Json).BASTION_NAME)
    $resourceGroupName = ((azd env get-values --output json | ConvertFrom-Json).BASTION_RESOURCE_GROUP)
    $targetResourceId = ((azd env get-values --output json | ConvertFrom-Json).JUMPBOX_RESOURCE_ID)
  4. Run the following command to create a bastion tunnel to the jump box:

    az network bastion tunnel --name $bastionName --resource-group $resourceGroupName --target-resource-id $targetResourceId --resource-port 22 --port 50022

    NOTE

    Now that the tunnel is open, change back to use the original PowerShell session to deploy the code.

  5. Run the following command to restore packages and compile code.

    azd package
  6. Install the SSH extension for Azure CLI

    az extension add --name ssh
  7. Obtain an SSH key from entra:

    az ssh config --ip 127.0.0.1 -f ./ssh-config
  8. From PowerShell use the following rsync command to upload the code to the jump box using the ssh config exported above:

    rsync -av -e "ssh -F ./ssh-config -p 50022" . 127.0.0.1:~/web-app-pattern

    If you were unable to connect due to Remote host identification has changed

  9. Run the following command to start a shell session on the jump box using the ssh config exported above:

    ssh -F ./ssh-config 127.0.0.1 -p 50022

4. Deploy code from the jump box

  1. Change to the directory where you uploaded the code:

    cd web-app-pattern
  2. Change the exeuatable permissions on the scripts:

    chmod +x ./infra/scripts/**/*.sh
  3. Start a PowerShell session:

    pwsh
  4. Sign in to Azure PowerShell interactively:

    Connect-AzAccount -UseDeviceAuthentication
    Set-AzContext -SubscriptionId ((azd env get-values --output json | ConvertFrom-Json).AZURE_SUBSCRIPTION_ID)
  5. Sign in to azd:

    azd auth login --use-device-code
  6. Deploy the application to the primary region using:

    azd deploy

    It takes approximately 5 minutes to deploy the code.

    WARNING

    In some scenarios, the DNS entries for resources secured with Private Endpoint may have been cached incorrectly. It can take up to 10-minutes for the DNS cache to expire.

  7. Deploy the application to the secondary region using:

    azd env set AZURE_RESOURCE_GROUP ((azd env get-values --output json | ConvertFrom-Json).SECONDARY_RESOURCE_GROUP)
    azd deploy
  8. Use the URL displayed in the console output to launch the Relecloud application that you have deployed:

    screenshot of Relecloud app home page

5. Teardown

  1. Close the PowerShell session on the jump box:

    exit
  2. Close your SSH session:

    exit
  3. Close your background shell that opened the bastion tunnel with the interrupt command Ctrl+C.

  4. To tear down the deployment, run the following command from your dev container to remove all resources from Azure:

    azd down --purge --force