🔥 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).
# 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.
If you want to follow along, you'll need the following:
- An Azure subscription (If you don't have an Azure subscription, create a free account (opens new window) before you begin)
- A computer that is onboarded to Azure Arc-enabled servers. You can follow part 1 of this series of posts (opens new window) to get started
- The Arc-enabled server needs to adhere to all of the prerequisites (opens new window), including having a Kubernetes cluster, the Azure CLI, and more
# 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:
- On the Arc-enabled computer, start a command prompt
- 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
- 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
- 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
After a while, the Kubernetes cluster is connected to Azure Arc.
- Go to the Azure portal (opens new window)
- Search for "Azure Arc" in the search box and click on the result. You will now see the Azure Arc overview blade
- Navigate to the Kubernetes clusters menu
- You'll see the connected Kubernetes cluster. Click on it
(Arc-connected Kubernetes cluster)
- 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)
- 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
- Click Add
- Select Application service extension, and then click Create
- Fill in a Name for the extension
- For Custom location, click Create new and fill in a Name and Namespace, like "appservice"
- Next, you'll need the publicly reachable static IP address that your local Kubernetes cluster uses. Use it for Static IP
- Leave Storage class as is
- Click Next
- For now, leave Enable logs unchecked
- Click Next
- And click Next again
- Now copy the script
(Add App Service extension for Azure Arc wizard)
- Go to the Arc-enabled computer that runs the Kubernetes cluster
- Open an elevated PowerShell prompt
- 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
- 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
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)
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!