14 July, 2021

3. Azure Arc : Running Azure App Service in Azure Arc Enabled K8s

In the first article of my Azure Azc series; we have successfully onboarded an Azure Kubernetes Service (AKS) cluster into Azure Arc enabled Kubernetes. If you haven't followed that yet, I highly recommend you to visit that article first and configure your clusters if you want to follow along.

1. Azure Arc : Setting up 'Kubernetes - Azure Arc' with AKS cluster

In this article we would run an Azure App Service - Web App inside our Azure Arc for Kubernetes cluster. 

Hang on! Just read the above statement again. Azure Arc is meant for hybrid, multi-cloud capability and running an application on that doesn't mean that we can run it on any cloud behind the scene? Yes, your are right 😊, your Azure App Service can now run anywhere; hardly matters its on-premise or on any other cloud provider's platform. Sounds Interesting! Let's dive.

  • Lets go inside the resource group (arc-rg-01 in my case) where we have both our Kubernetes service cluster and the Kubernetes - Azure Arc cluster.
  • We would need a public static IP address to configure our app service which we would see shortly. So, for now just go ahead and create a public ip address in the your managed cluster (MC_) resource group (because I am running my AKS cluster in Azure) before moving forward. I gave the name as "my-webapp-arc-pip" leaving all other setting as default.
  • Once done... copy the IP address and keep it in notepad. 
  • Search for "Azure Arc" in the search bar (azure portal) and select it from the result
  • Choose 'Kubernetes clusters' under Infrastructure to find your Azure Arc for K8s cluster.
  • Click on that, choose "Extensions (preview)" and then click +Add. The extension is in preview at the time of writing this article but its works perfectly. So, go ahead.
  • Select "Application services extension (Preview)"
  • Give your instance name, create a custom location and put the public ip address (copied to your notepad) in the static ip textbox. This custom location will show up in your azure region list once we configure the web app. This is again a magic which we will see shortly 😊
  • Click Next, Next and at the "Run Script" section, it will automatically generate the required PowerShell script which you need to download or copy to clipboard so that you can run it using any powershell platform. 
  • I just copied it to clipboard but don't run it straightway. We need to enable the custom-location feature for our k8s cluster (do not confuse this with arc cluster). This is a very important step often get missed; else the generated powershell script would fail throwing permission denied error. So, let's go ahead and run the below script. Replace the values as per your environment.
az extension add --name customlocation
az connectedk8s enable-features -n "<cluster-name" -g "<resource group>" --features cluster-connect custom-locations
  • Now run the generated PowerShell script.  I ran it using PowerShell ISE editor but you are free to use any of your choice. The script would take a while to finish, so go grab your favorite beverage and relax. I already took mine 🍺
  • On successful completion of the script, you will see the "microsoft.web.appservice" extension has been installed successfully in your cluster.
  • Now check the Custom locations under Management to find that the custom location has also been created successfully.

Great! now we are all set to create a app service (web app) and run in on out K8s Arc cluster. So, lets get goingπŸ˜‰
  • Click "App services" under Services and click to create a new web app
  • Now in the next screen before doing anything, click the region dropdown. Voila! our new custom region shows up. Yeah! its right there.... amazing. Select that.
  • Fill up other details as required. You might have also noticed by this time that url has also changed on change of custom location as a region. This is enough to tell us that this not an ordinary azure app service which we use to create. I have selected the runtime stack as .Net core  but you are free to choose any of your choice. Review and create.

  • Once complete, check the "App services" under Services to find our service.
  • Click on that and get the URL. Run it!


A big virtual High Five!!!! We have done it!. 

Now our Azure app service is running on Azure Arc for K8s cluster and the underlying cluster can be anywhere.. on-premise, any cloud provider's platform, wherever... We just do not mind πŸ˜‹

We can keep deploying our code to this app service manually, from VS or by DevOps pipeline and let Azure do all the heavy lifting to host that in a multi cloud platform.

Congratulations! for coming this far. Hope this article will help you to further explore more on this topic.

Do share with me about your experience and what you have built upon this foundation. You can take it upto any level and integrate. I would love to hear from you.

No comments:

Post a Comment