Deploy Micro-service to AKS(Azure Kubernetes Service) using Azure DevOps Pipeline (Build & Release)

Anas Solanki
4 min readJul 12, 2021

In this article, we are going to learn how to deploy any micro-service to AKS using Azure DevOps pipeline along with azure container registry. This article is having 2 section i.e Build and Release.

1 : Build Pipeline

1.1: Create docker file in your repository to build image

I am using Azure repositories for version control. Add your Dockerfile in your Project’s root directory as shown below:

1.1: Create docker file in your repository to build image

1.2: Manifests setup

Download manifests folder and copy it to your azure project repository using this link.

Note: you can add your own k8s yaml files if you want in the manifests folder.

1.3: Configuring app.yaml

Update app.yaml file as per the requirement from manifest folder as show below.

1.3: Configuring app.yaml

NOTE: docker container registry URL should be changed according to your registry name.

In my case, image name is sample-app. You can use image name as same as your azure project name.

Similarly change app-service.yaml file according to your needs.

Keep #{Build.BuildId}# in app.yaml file as it is. It will be used as an image tag.

1.4: New Build(CI) Pipeline

Go to azure project and select Pipelines and click on New pipeline.

Click on Use the classic editor link as shown below.

1.4: New Build(CI) Pipeline

1.5: Pipeline repo setup

1.5: Pipeline repo setup

Select Azure Repos Git to pull your code from repository

Select project under Team project & Repository drop down and default branch for build and click Continue.

1.6: Select ‘Empty Job’ as template

1.6: Select ‘Empty Job’ as template

1.7: Pipeline Agent Setup

Set pipeline name, select Azure Pipelines from agent pool dropdown and ubuntu-20.04 from agent specification dropdown respectively.

1.7: Pipeline Agent Setup

1.8: Agent Job Setup

  • Click on the + icon on the right of Agent Job Name to add a task.
  • Search for docker and select as shown below
1.8: Agent Job Setup
  • Fill the details as desired, but let Action, Docker file & Image name be the same as shown below.
1.8: Agent Job Setup
  • Repeat above steps with name Push an image. This is to push the built image to ACR as shown below
1.8: Agent Job Setup

1.9: Copy Manifests

Create a new task and search Copy files and add it to the task list. This is to copy all manifests file to artifact directory.

1.9: Copy Manifests

Fill in the details for task as shown below

1.9: Copy Manifests

1.10: Publish Artifact

Add Publist Artifact:drop task to agent job list and fill in the details as shown below, then click Save & queue.

1.10: Publish Artifact

2: Release Pipeline

2.1: New Release Pipeline

Create a new release pipeline by clicking on Releases from the left panel.

2.2: Add Artifact

Click on Add an Artifact and set source type as Build. Fill project name as it is, default version as latest & source build pipeline as the pipeline we created earlier, respectively.

2.2: Add Artifact

In my case build pipeline name which we created earlier in the first part in “Document-Manager-CI”. It will take the latest artifact pushed by the build pipeline.

Stage name can be modified.

2.3: Replace Token

Create new task by clicking on + icon and search for Replace Token. Add this task to our agent job list.

Edit the task and set **/app.yaml in target field as shown below

2.3: Replace Token

Edit the task and set **/app.yaml in target field as shown below

2.3: Replace Token

app.yaml is k8s deployment file which will add build number to image tag. Ex — If build id is 420, #{Build.BuildId}# will be replaced by 420 in app.yaml file

2.4: kubectl Configuration

  • Edit kubectl task and add kubernetes cluster connection and choose apply command from the commands dropdown.
  • Mark Use Configuration as checked.
  • Select Configuration as File Path
  • Browse to the manifests file and select
  • Save the release pipeline
2.4: kubectl Configuration
  • Run the pipeline by clicking on Create Release

Thanks for reading.

--

--

Anas Solanki

DevOps Engineer | CICD | GCP | AzureDevOps | Kubernetes | Linux Administrator | Redhat