Orchestrating .Net Core Application Using Azure Kubernetes Service

Introduction 

 
In this article, I am going to talk about orchestrating containers developed in (.NET Core technology) using Azure Kubernetes service. The service can be consumed by any front-end application like HTML, etc., I will be demonstrating in a step-by-step manner how to create Kubernetes cluster and deploy the ASP.NET Core application image into Azure registry and then how Kubernetes cluster maintains those internal container instances automatically.
 
Please refer to my article how to deploy local docker image into azure regsitry, this will be useful to deploy your local docker image into Azure container registry. We will focus only on Kubernetes services in this article. 
 
Pre-requisite
 
 

Orchestrating containers using Kubernetes

 
Step 1
 
Go to Azure Portal and open cloud shell on right top corner(>_) to create secrets and to deploy images from container registry to Kubernetes.
 
Step 2
 
Create Image pull secret to secure image using the same credential of container registry.
  1. kubectl create secret docker-registry trainings --docker-server= trainingservice1.azurecr.io --docker-username= trainingservice1 --docker-password= lddH+ejcVXQf81nNWP3C9bTOA  
'trainings' is the name of secrets and docker-server is the login server name from container registry and docker-username and password is container registry username and password.
 
Step 3
 
Create new Resource -> Containers -> Kubernetes Service (AKS cluster), with Node count two, this node will be used to load balance in case of more requests which are taken care of by Kubernetes services. You can keep all other parameter values as default.
 
Orchestrating .Net Core Application Using Azure Kubernetes Service
 
If you are using the free trial and face the error "The subscription is not registered to use namespace 'Microsoft.Network'. then go to your subscription->resource Provider and register the Microsoft.network namespace and perform  step 3 again.
 
Step 4
 
The next step is to create yaml file with all configuration of nodes, service, type(LoadBalancer), name etc and upload into default cloud shell storage account and then deploy into AKS cluster. Open cloud shell and upload the yamal file. yamal file is attached for refernce.
  1. kubectl create -f .\traningservice-deploy.yaml  
Step 5
 
Once the deployment is sucessful, you can get service details created in the previous step by executing the below command. 
  1. kubectl get service my-trainingapp-svc –watch  
Here, my-trainingapp-svc is a service name defined under service definition->metadata->name in ymal file.
 
Orchestrating .Net Core Application Using Azure Kubernetes Service
 
When we deployed this microservice into docker on a local machine, the service URL was generated as https://localhost:44382/TrainingService and after deploying the same service into the Azure container the URL of service is https://containerIPaddress/trainingservice and now the service url is https://52.242.225.46/trainingservice when service is deployed into Kubernetes and containers are managed by Kubernetes cluster. Finally, this Azure service can be deployed/consumed by any of your front-end applications.
A few more commands to get pods and delete pod:  If you delete the one pod, Kubernetes creates another pods automatically.
  1. kubectl get pods  
  2. kubectl get service
  3. kubectl delete pod podname  
Orchestrating .Net Core Application Using Azure Kubernetes Service
 

Summary

 
Here, we learned to deploy Microservices developed in .NET Core language into Azure Kubernetes (using Azure container registry) from the local docker image.