TIP

🔥 Help shape the future of Azure Tips and Tricks by telling what you'd like for us to write about here (opens new window).

💡 Learn more : Azure Kubernetes Service overview (opens new window).

📺 Watch the video : How to run an App Service Web App on Azure Arc-enabled Kubernetes - Part 2 (opens new window).

# How to run an App Service Web App on Azure Arc-enabled Kubernetes - Part 2

# Manage Kubernetes from Azure

Kubernetes is a powerful container orchestrator technology that enables you to run a solution with many containers. Azure Arc (opens new window) can make your Kubernetes cluster part of Azure so that you can manage it from Azure, just like an Azure Kubernetes Service (opens new window). And you can use that Kubernetes cluster as compute to run other services, like App Service (opens new window), Event Grid (opens new window), and API Management Gateway (opens new window).

This post is the second part of a series of three. In this post, we'll add a Kubernetes cluster to Azure using Azure Arc-enabled Kubernetes (opens new window) and run an App Service Web app (opens new window) on it.

# Prerequisites

If you want to follow along, you'll need the following:

# Add Kubernetes to Azure Arc

I have a computer that is Arc-enabled, and managed by Azure. It runs Docker Desktop with a Kubernetes cluster enabled (opens new window) in it. I can manage the health and configuration of the computer from Azure, but I can't manage the Kubernetes cluster from Azure yet. Let's change that.

Before you can onboard a Kubernetes cluster to Azure Arc, you need to make sure that the machine that runs the cluster adheres to all of the requirements (opens new window).

(Prerequisites before adding a Kubernetes cluster to Azure Arc)

When your machine and cluster are ready, you can add the cluster:

  1. On the Arc-enabled computer, start a command prompt
  2. Login to Azure using az login. This will ask you for your credentials. If you have multiple Azure subscriptions, you might need to select the subscription (opens new window) that you want to use
  3. Next, create a resource group using the command below. This will be used to connect Kubernetes to Azure
az group create --name AzureArcTest --location EastUS --output table
1
  1. Use the next command to connect Kubernetes to Azure Arc. Use the name of the resource group and pick a name for how the Kubernetes cluster should be named in Azure. This can take 5 to 10 minutes to complete
az connectedk8s connect --name [kubernetes context name] --resource-group AzureArcTest
1

After a while, the Kubernetes cluster is connected to Azure Arc.

  1. Go to the Azure portal (opens new window)
  2. Search for "Azure Arc" in the search box and click on the result. You will now see the Azure Arc overview blade
  3. Navigate to the Kubernetes clusters menu
  4. You'll see the connected Kubernetes cluster. Click on it

(Arc-connected Kubernetes cluster)

  1. Now, you can manage the cluster from Azure and monitor it. Click on the Insights menu. You might need to enable monitoring. When that is done, you'll see performance and health metrics of the Kubernetes cluster. You can even drill down into its Nodes

(Drill down into node metrics of the Arc-connected Kubernetes cluster)

  1. Let's do something really cool. You can use the Kubernetes that is running on the Arc-enabled machine, as compute to run other services, like App Services (opens new window). Click on the Extensions menu
  2. Click Add
  3. Select Application service extension, and then click Create
    1. Fill in a Name for the extension
    2. For Custom location, click Create new and fill in a Name and Namespace, like "appservice"
    3. Next, you'll need the publicly reachable static IP address that your local Kubernetes cluster uses. Use it for Static IP
    4. Leave Storage class as is
    5. Click Next
    6. For now, leave Enable logs unchecked
    7. Click Next
    8. And click Next again
    9. Now copy the script

(Add App Service extension for Azure Arc wizard)

  1. Go to the Arc-enabled computer that runs the Kubernetes cluster
  2. Open an elevated PowerShell prompt
  3. Paste in the script that we've generated in the Azure portal. This will prompt you to sign in to Azure and might ask you to allow network traffic through a firewall. Wait until the script is done. This can take a while
  4. When the script is finished, an App Service environment is running in the Kubernetes service on the local machine. Now, we can create App Services, like a Web App, in it. The PowerShell script below creates a new Web App in the environment and deploys a sample Node.js application from a GitHub repo into it. Change the parameters for resourceGroup, customLocationName, appServicePlanName, and webAppName to your values.
$resourceGroup="AzureArcTest"
$customLocationName="tipsapploc"
$appServicePlanName="ArcAppPlan"
$webAppName="MyArcTipsAppService"

$customLocationId=$(az customlocation show --resource-group $resourceGroup --name $customLocationName --query id --output tsv)

az appservice plan create -g $resourceGroup -n $appServicePlanName --custom-location $customLocationId --per-site-scaling --is-linux --sku K1

az webapp create --plan $appServicePlanName --resource-group $resourceGroup --name $webAppName --custom-location $customLocationId --% --runtime 'NODE|12-lts'

git clone https://github.com/Azure-Samples/nodejs-docs-hello-world
cd nodejs-docs-hello-world
Compress-Archive -Path * -DestinationPath package.zip
az webapp deployment source config-zip --resource-group $resourceGroup --name $webAppName --src package.zip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

After running the script, you can check in the Azure portal if the App Service Web App shows up. You'll see it when you go to the App Services resource. It has most of the normal App Service Web App features.

(App Service Web App running on Kubernetes)

When you visit the Web App URL, you'll see the sample application, which is a simple page that says "Hello world!".

(Sample application running in an App Service on Kubernetes, on a on-premises computer)

# Conclusion

Azure Arc (opens new window) can use an Arc-enabled Kubernetes cluster (opens new window) as compute for services like App Service (opens new window). This enables you to run App Services like Web Apps (opens new window) and Functions (opens new window) on your machine that runs on-premises, on the edge, or in another data center. Go and check it out!