Deploy ASP.NET Core Application on AKS with Helm through Azure DevOps.

Shyam Mohan K
5 min readJun 18, 2021

While working at Kubeify, we did a workshop and Client Migration to Azure AKS. In workshop we used an asp.net core demo app, and we automate the build and used helm charts in release pipeline to deploy it to the kubernetes (AKS).

repo: https://github.com/saurabhsy8/aspnetapp

Task to do:

  1. Create Azure container registry.
  2. Create AKS cluster.
  3. Dockerfile
  4. Helm Chart
  5. Create build pipeline (Docker build and push)
  6. Create release pipeline (deploy app to aks)

Let’s start with creating azure container registry.

1. Azure container registry

I already created a registry with name of netdemo, but I create new one just to understand:

For now we don’t need AZ and private endpoint.

Leave encryption as it is and got to Review + create. Now we have our own private container registry 🥳, for accessing this registry from docker CLI we need credentials, so to get credentials we need to enable admin user: go to Access keys and enable Admin user 👍.

2. Create AKS cluster

Node Pools:

Note: For running windows container we need windows nodes so to do so we will create two node pool: It is not necessary to have two nodes in each node pool you can go with one node in each pool but remember the node size must be Standard_D2s_v3 or greater in size.

After creating node pools continue with default values and at last Review + create.

3 Dockerfile

Let’s understand Dockerfile:

we are using multi stage build so that we can reduce image size here, in first stage we restore dependencies and publishing it, In last stage we copy published solution.

Note: If we can see in both stage we are using different base image, in first stage we use full sdk just to publish the project and in last we use only runtime to just run the published project 👍.

4 Helm Chart

We are using very simple helm chart in which we have only deployment and it’s service to expose the app.

deployment.yaml is simple: we expose the container at port 80 with name http.
we expose the service at 80 with target port http (named port) which is 80:

5 Create build pipeline (Docker build and push)

Navigate to your Azure DevOps create new project.

Then, if you don’t want to use azure git you can skip this step:

Create new git repo, after creating, you can export project from github.

Now let’s create pipeline: Choose your respective repository, I am using agr

after selecting repo: Select the 2nd one Build and push an image to Azure Container Registry

Now choose you subscription: It will pop-up sign-in page, so do so

after this we will get to see: choose the container registry we just made above.

Note: Before this you need to add service connection.

after validate and configure we will see (azure-pipelines.yml) something like this: we need to change vmImageName: ‘ubuntu-latest’ to vmImageName: ‘windows-latest’ and I just changed tag: ‘$(Build.BuildId)’ to tag: ‘$(Build.SourceVersion)’.

Now our build pipeline is ready and you must be able to trigger build at changes.

6 Create release pipeline (deploy app to aks)

Since I have helm charts in my main git repo so I just need to use git repo it as Artifacts:

In stage add helm template:

Now let’s edit tasks, first set right agent pool:

For our purpose Agent Specification must be windows-2019.

Let’s add helm: we need two helm command

  1. helm install
  2. helm upgrade

For Apply Helm chart job: you can take reference from this yaml and can create this job through UI as well, as we can see we define our cluster information as well so that helm can connect to kubernetes.

For Upgrade Helm chart job: we can see condition in both jobs are different because we want to run helm install command at first run and after that it just need to upgrade charts.

So this is it we have created our CI/CD pipeline in azure devops.

--

--

Shyam Mohan K

Founder at RazorOps CICD, I love Container Native DevOps with Docker and Kubernetes, SO