Deploy an App Service app using custom container on Cluster API using an ARM Template

The following README will guide you on how to deploy a “Ready to Go” environment so you can start using Azure Arc-enabled app services deployed on Cluster API (CAPI) Kubernetes cluster and it’s Cluster API Azure provider (CAPZ) cluster using Azure ARM Template.

By the end of this guide, you will have a CAPI Kubernetes cluster deployed with an App Service plan, a sample Web Application (Web App) and a Microsoft Windows Server 2022 (Datacenter) Azure VM, installed & pre-configured with all the required tools needed to work with Azure Arc-enabled app services.

Note: Currently, Azure Arc-enabled app services is in preview.

Prerequisites

  • Clone the Azure Arc Jumpstart repository

    git clone https://github.com/microsoft/azure_arc.git
    
  • Install or update Azure CLI to version 2.25.0 and above. Use the below command to check your current installed version.

    az --version
    
  • Generate SSH Key (or use existing ssh key).

  • Create Azure service principal (SP)

    To be able to complete the scenario and its related automation, Azure service principal assigned with the “Contributor” role is required. To create it, login to your Azure account run the below command (this can also be done in Azure Cloud Shell.

    az login
    az ad sp create-for-rbac -n "<Unique SP Name>" --role contributor
    

    For example:

    az ad sp create-for-rbac -n "http://AzureArcAppSvc" --role contributor
    

    Output should look like this:

    {
    "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "displayName": "AzureArcAppSvc",
    "name": "http://AzureArcAppSvc",
    "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
    

    Note: It is optional, but highly recommended, to scope the SP to a specific Azure subscription.

Architecture (In a nutshell)

From the Cluster API Book docs:

“Cluster API requires an existing Kubernetes cluster accessible via kubectl; during the installation process the Kubernetes cluster will be transformed into a management cluster by installing the Cluster API provider components, so it is recommended to keep it separated from any application workload.”

In this guide and as part of the automation flow (described below), a Rancher K3s cluster will be deployed which will be used as the management cluster. This cluster will then be used to deploy the workload cluster using the Cluster API Azure provider (CAPZ).

Automation Flow

For you to get familiar with the automation and deployment flow, below is an explanation.

  • User is editing the ARM template parameters file (1-time edit). These parameters values are being used throughout the deployment.

  • Main azuredeploy ARM template will initiate the deployment of the linked ARM templates:

    • ubuntuCapi - Deploys an Ubuntu Linux VM which will have Rancher K3s installed and transformed into a Cluster API management cluster via the Azure CAPZ provider.
    • clientVm - Deploys the client Windows VM. This is where all user interactions with the environment are made from.
    • mgmtStagingStorage - Used for staging files in automation scripts.
    • logAnalytics - Deploys Azure Log Analytics workspace to support Azure Arc-enabled app services logs uploads.
  • User remotes into client Windows VM, which automatically kicks off the AppServicesLogonScript PowerShell script that will configure Azure Arc-enabled app services Kubernetes environment on the CAPI cluster.

Deployment

As mentioned, this deployment will leverage ARM templates. You will deploy a single template that will initiate the entire automation for this scenario.

  • The deployment is using the ARM template parameters file. Before initiating the deployment, edit the azuredeploy.parameters.json file located in your local cloned repository folder. An example parameters file is located here.

    • sshRSAPublicKey - Your SSH public key
    • spnClientId - Your Azure service principal id
    • spnClientSecret - Your Azure service principal secret
    • spnTenantId - Your Azure tenant id
    • windowsAdminUsername - Client Windows VM Administrator name
    • windowsAdminPassword - Client Windows VM Password. Password must have 3 of the following: 1 lower case character, 1 upper case character, 1 number, and 1 special character. The value must be between 12 and 123 characters long.
    • myIpAddress - Your local public IP address. This is used to allow remote RDP and SSH connections to the client Windows VM and CAPI cluster nodes.
    • logAnalyticsWorkspaceName - Unique name for the deployment log analytics workspace.
    • deployAppService - Boolean that sets whether or not to deploy App Service plan and a Web App. For this scenario, we leave it set to true.
    • deployFunction - Boolean that sets whether or not to deploy App Service plan and an Azure Function application. For this scenario, we leave it set to false.
    • deployLogicApp - Boolean that sets whether or not to deploy App Service plan and an Azure Logic App. For this scenario, we leave it set to false.
    • deployApiMgmt - Boolean that sets whether or not to deploy App Service plan and an Azure Logic App. For this scenario, we leave it set to false.
    • templateBaseUrl - GitHub URL to the deployment template - filled in by default to point to Microsoft/Azure Arc repository, but you can point this to your forked repo as well.
  • To deploy the ARM template, navigate to the local cloned deployment folder and run the below command:

    az group create --name <Name of the Azure resource group> --location <Azure Region>
    az deployment group create \
    --resource-group <Name of the Azure resource group> \
    --name <The name of this deployment> \
    --template-uri https://raw.githubusercontent.com/microsoft/azure_arc/app_svc_capi/azure_arc_app_services_jumpstart/cluster_api/capi_azure/arm_template/azuredeploy.json \
    --parameters <The *azuredeploy.parameters.json* parameters file location>
    

    Note: Make sure that you are using the same Azure resource group name as the one you’ve just used in the azuredeploy.parameters.json file

    For example:

    az group create --name Arc-AppSvc-Demo --location "East US"
    az deployment group create \
    --resource-group Arc-AppSvc-Demo \
    --name arcappsvc \
    --template-uri https://raw.githubusercontent.com/microsoft/azure_arc/app_svc_capi/azure_arc_app_services_jumpstart/cluster_api/capi_azure/arm_template/azuredeploy.json \
    --parameters azuredeploy.parameters.json
    

    Note: The deployment time for this scenario can take ~5-10min

    Note: Since Azure Arc-enabled app services is currently in preview, deployment regions availability is limited to East US and West Europe.

  • Once Azure resources has been provisioned, you will be able to see it in Azure portal. At this point, the resource group should have 34 various Azure resources deployed.

    ARM template deployment completed

    New Azure resource group with all resources

Windows Login & Post Deployment

  • Now that first phase of the automation is completed, it is time to RDP to the client VM using it’s public IP.

    Client VM public IP

  • At first login, as mentioned in the “Automation Flow” section above, the AppServicesLogonScript PowerShell logon script will start it’s run.

  • Let the script to run its course and do not close the PowerShell session, this will be done for you once completed. Once the script will finish it’s run, the logon script PowerShell session will be closed, the Windows wallpaper will change and the Azure web application will be deployed on the cluster and be ready to use.

    Note: As you will notices from the screenshots below, during the Azure Arc-enabled app services environment, the log-processor service pods will be restarted and will go through multiple Kubernetes pod lifecycle stages. This is normal and can safely be ignored. To learn more about the various Azure Arc-enabled app services Kubernetes components, visit the official Azure Docs page.

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    PowerShell logon script run

    Once the script finishes it’s run, the logon script PowerShell session will be closed, the Windows wallpaper will change, and both the app service plan and the sample web application deployed on the cluster will be ready.

    Wallpaper change

  • Since this scenario is deploying both the app service plan and a sample web application, you will also notice additional, newly deployed Azure resources in the resources group. The important ones to notice are:

    • Azure Arc-enabled Kubernetes cluster - Azure Arc-enabled app services are using this resource to deploy the app services cluster extension, as well as using Azure Arc Custom locations.

    • Custom location - Provides a way for tenant administrators to use their Azure Arc-enabled Kubernetes clusters as a target location for deploying Azure services.

    • App Service Kubernetes Environment - The App Service Kubernetes environment resource is required before apps may be created. It enables configuration common to apps in the custom location, such as the default DNS suffix.

    • App Service plan - In App Service (Web Apps, API Apps, or Mobile Apps), an app always runs in an App Service plan. In addition, Azure Functions also has the option of running in an App Service plan. An App Service plan defines a set of compute resources for a web app to run.

    • App Service - Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends.

    Additional Azure resources in the resource group

  • In this scenario, a Docker, custom container Linux-based sample Jumpstart web application was deployed. To open the deployed web application in your web browser, simply click the App Service resource and the Browse button.

    App Service resource in a resource group

    App Service Browse button

    App Service open in a web browser

Cluster extensions

In this scenario, the Azure Arc-enabled app services cluster extension was deployed and used throughout this scenario in order to deploy the app services infrastructure. In addition, both the Azure Monitor for Containers and the Azure Defender extensions were also installed on the cluster.

  • In order to view cluster extensions, click on the Azure Arc-enabled Kubernetes resource Extensions settings.

    Azure Arc-enabled Kubernetes resource

    Azure Arc-enabled Kubernetes cluster extensions settings

Cleanup

  • If you want to delete the entire environment, simply delete the deployed resource group from the Azure portal.

    Delete Azure resource group