Monday, December 24, 2018

Deploy ASP.NET Core App to AKS with Azure DevOps

When start a new application development, we have to invest on initial effort in creating required project structure,configure CI/CD pipelines etc. to facilitate the successful application development.In a situation where you target Azure Kubernetes Services as deployment target of your application you can use Azure DevOps project to do the initial setup within few minutes.
This post will explain how create a new DevOps project with full CI/CD pipeline to get ASP.NET core application deployed to AKS.Let’s look at steps in detail.

  • Go to Azure portal (https://portal.azure.com )
  • Create a new DevOps project.To create a project, first search “DevOps” and select DevOps project from the suggested list.
NewDevOpsproj
  • Click on the Create DevOps project button
CreateDevOpsproj
  • You can select your preferred development platform among suggestions.For this post let’s choose .NET.Then click on Next button and move to next step.
Selectlanguage
  • You can select the framework in second step and also have an option to add database to your application. Select ASP.NET Core application and don’t select a database.Click Next and move to next step.
Framework
  • Here you can select the Azure service to deploy your application.I select Kubernetes Service.Then click Next.
selectAKs
  • So far you have selected the technologies that you are going to use with your application development process.Now you can give name of the DevOps project.Azure DevOps project will be created with git repository to keep source code and full CI/CD pipelines.Provide a project name and select Azure DevOps organization.Other than those you can see the cluster name and Location.Change location to preferred region.After that click on Additional settings link.
AddProjname
  • Under additional setting section, you have option to create a new DevOps organization or use existing organization.In this blog post we use an existing organization.Then you can see new resource group is created to AKS.Change all locations to preferred region.Change the number of nodes in the AKS cluster according to your requirement.Within this deployment process, we are going to create a docker image and we need a place to store it before we deploy it as a container to AKS.For that purpose we create an Azure Container Registry.In container registry area you can see the container registry name.Change the Location to a preferred region and select Container register SKU as per the requirements.These SKUs provide several options for aligning to the capacity and usage pattern of Docker registry in Azure.
AdditionalSettings
  • Click OK and then Done to start the deployment.
ProjDeployment
  • After Deployment completed go to Azure DevOps organization.You would be able to find newly created project.
AzureDevOpsProj
  • Select the project and go to Repos.You can see ASP.NET Core application has created.If you expand the project folder would be able to find the Docker file inside the project folder.This docker file is used to create a docker image of the ASP.NET Core application.Other than project folder there is another folder named ARM Template.Inside this folder you can find three ARM templates which can be used to deploy App Insight,Azure Container Registry and AKS cluster.
RepoContent
  • Now let’s move to build section and you would be able to see a triggered build.Let’s move to build definition and try to identify the build steps.
  • You can see Hosted Ubuntu server is used as build server and purpose of each step can be identified as follows.
1 – Deploy Azure container registry using ARM template
2 – Build docker image using docker file
3 – Push docker image to Azure Container Registry
4 – Add Helm packages to build drop to enable deployment to AKS based on Helm.Helm helps to manage Kubernetes applications.You can read more about Helm here( https://helm.sh/)
build
  • Let’s open the succeed build and find the build id using the URL as follows.You can see build id is 6.
BuildID
  • After build completed successfully there should be a container registry and image file with build id as tag.Let’s check the container registry and image file of our DevOps project.To do that, go to Azure portal and search for AKSDemo.Select AKSDemoacr among search results.
AKSacr
  • Then go to repositories section and select repository aksdemo.Inside the aksdemo repository,you would be able to find an image file with build id as tag.You can see an image file with number 6 as tag in the following image
.acrRepo
  • Now let’s move to release pipeline.You would be able to move to release definition and find steps as follows.
1 – Deploy AKS cluster using ARM templates
2 – Deploy image from Azure Container Registry to AKS using Helm packages steps
Relese
  • Let’s move back to Azure portal.Search for AKSDemo and select DevOps project among results.
SelectDevOpsProjAKsDemo
  • In the DevOps project dashboard will be opened and you can find the links to each part of Azure DevOps project.
1 – You can move to project Repos
2 – You can move to build pipelines and observer the status of triggered builds
3 – You can move to release pipeline and observer the status of the triggered release
4 – You can move to commits
5 – You can find the URL of the application
6 – You can access to more AKS cluster details
7 – You can move to main areas of azure DevOps project from this area.
DevOpsDashbard
  • So far you learned on how to create a project with full CI/CD pipeline and identified each steps of getting an ASP.NET Core application deployed to AKS.Your ASP.NET Core application is deployed to AKS and ready with full CI/CD to enable you to implement your business logic.You can access the application by clicking on sampleapp URL in the DevOps project dashboard.
SampleApp
  • If the deployment succeed without any issues, then you can see your sample ASP.NET Core application.
App

1 comment: