Monday, September 14, 2020

Deploying dockerized .net microservice to Kubernetes cluster using Azure DevOps YAML pipeline


In my previous blog https://www.leogether.com/2020/09/creating-kubernetes-cluster-with-azure.html

I created the Azure Container Registry and Kubernetes cluster using Terraform and Azure DevOps. I would encourage you to read my previous blog first before reading this.

In this blog, I will show you how to import a docker image into the Azure Container registry and deploy the application in the Kubernetes cluster using the Azure DevOps YAML pipeline. The complete architectural flow is as below:




I am using .net sample application that I had been using in my previous blogs:

 https://github.com/Pujago/studentregistration

My application code also has:

1. Docker file

2. Docker Compose file

3. 2 YAML files needed for Kubernetes:

    https://github.com/Pujago/studentregistration/tree/master/DeploymentK8s

    deployment.yml - It  is a YAML for kind deployment and service, for .net application

    mssql-deployment.yml - It  is a YAML for kind deployment and service, for sql server


Creating Azure DevOps project

Create a new project as below:

Go to the project and click on the Repos.

I have added my code in Azure DevOps Repos as below:


Creating service connections:

Create service connections for docker, Kubernetes, and Azure to communicate with DevOps as below:


Creating an Azure DevOps Pipeline:

Go to the project and click on the Pipelines, create a new pipeline "Deploy .net microservice in Kubernetes", follow the screen choices create a starter pipeline.

Replace the existing code with the code located in the file here:

The above YAML pipeline tasks are explained with comments in the file.

Once done, save and run the pipeline, you will see as below:



Once the pipeline runs successfully, Go to Azure Portal and select the Azure Container Registry. You will see the image is pushed to the container registry:


And also services are deployed to the Kubernetes cluster.

Now let's connect to the cluster. 

Using Azure CLI, run the following commands:

To connect: 
az login

To set the current context in Kube config:
az aks get-credentials --name eks_dev --resource-group kubernetes_dev

To see services running:
kubectl get svc


Use the external IP address to test your service in Postman:


Happy reading!

2 comments:

  1. I really like the way it is explained in such simple terms.. Superb. Thanks.

    ReplyDelete
  2. This information is really awesome thanks for sharing most valuable information.
    Workday Training
    Workday Online Training

    ReplyDelete