SlideShare a Scribd company logo
1 of 16
Download to read offline
Dockerized .net core application with AK8s
services
***Symbols are subject to copy right for Microsoft
Develop .Net Core Application
with Azure Kubernetesservices
#AKS #Azure #AppsServise #CloudApps #Docker #.netCore
Posted by Ranjeet Bhargava on August 02 2019.
Now a day we are living in the hyper scaled digitalized world where everyone is connected
direct or indirect - loosely or tightly with Apps or I can say Virtually Apps are surrounded
with use all the time.
Today I would like to share my experience on the Devops specific to the Dockers containers and
Kubernetes with -Azure Apps Services -API Integrations for micro services architecture which
evolved to boost up by solving problems and shortcomings of monolithic applications.
Containerizations ref as Portable Containers (K8s) here - by Docker /Kubernetes platforms are
now made faster and easy to bundle the applications’ packages & placing the deployments quickly.
 Azure K8s platform helps us to
create deployments, orchestrate
the deployments on demand and
manages applications under the
hoods.
 Microsoft’s Azure Kubernetes
Services (AKS) is cloud hosting
services which provide built-in
Kubernetes services that help you
to orchestrate cloud-hosted
functions and microservices in
their environment.
So friends we will be engaged for just three practices ABC as below [.Net Core Application]
a) 1st we will create one ASP.NET Core web application.
b) 2nd we will containerize this application with Docker.
c) 3rd we will deploy this on AKS cluster.
Please don’t worry about the functionalities of this application as we’ll use it for the deployment only that
can explain where it’s running and it is scaled. Our focus would be on creating the containers and using
Kubernetes to deploy the application to an AKS cluster. When the application is dockerized, we’ll create a
local image of the application to test locally.
Pre-Requisite
1. Git for Windows
2. .NET Core 2.1 or above
3. Azure CLI
4. Azure PowerShell
5. Docker for Windows Click to Install Docker
We will require a valid Azure account for the deployment, and we’ll be using the following applications on
the development machine. When docker for Windows is installed and running, then goes to the settings
and enable the checkbox for Kubernetes as shown below:
If in your environment is docker for Windows should be running in Linux container mode,
otherwise, the Kubernetes option will not be shown in the settings. Then do the Azure CLI
installation, run the following command (az --version) to make sure the CLI is up and
running.
Now you should clone or download the code from below Git Repository project:
https://bhargavaonline.visualstudio.com/AKS%20with%20ASP.Net%20Core%20Application
 Application Setups:
Next step after cloned or downloaded and unzipped, execute the dotnet run command as
shown below. This will run the server and tell on what port the server is listening for the application,
i.e., http://localhost:5000.
You can follow these steps with Applications which you might be created at your end.
Now open the browser and try http://localhost:5000.
Check it’s just a simple application showing the host or container in which the application is running.
Currently, it runs on a development windows machine without a container and so it shows the name of
the host machine, in this case 3593BH2.
 Setting Docker [Container]
We will use Docker to create a container for the application. Alternately you can download the sample
code. After creating container Navigate to the root of the application directory to see the already created
docker file. This Dicker’s file will be used to build the image.
The runtime image is built using the docker build command as shown below:
Hide Copy Code
docker build . -t aks:local
Make sure that you are in the directory that contains a Docker file and then run the command. If you’re
not familiar with the syntax, the dot indicates that the Docker file is located in the current directory and the
-t switch allows you to specify the tag aks:local.
This kicked start the build process.
Once the build completes, run the docker image list command. It lists a brand-new image called
aks:local.
To test this image, run a container based on this image by using the docker run command:
Hide Copy Code
docker run -d -p 5000:80 aks:local
The -d switch tells Docker to run this as a daemon process. The -p switch maps port 5000 on the host to
local port 80 on the container.
Execute command docker ps to see the container up and running.
Now go to the browser and connect to http://localhost:5000.
We see the application now running under docker container as the hostname now shows the ID of the
container here.
Delete the newly created test container by running:
Hide Copy Code
docker container rm -f [container name]
For [container name], substitute the ID of the container as displayed in your browser or by running the
docker ps command.
 Deploy on a Local Kubernetes Cluster
So now, we have to quickly deploy the application to a local Kubernetes cluster to illustrate the manual
approach to orchestration with Kubernetes.
This will provide a baseline to compare with Kubernetes orchestration with AKS. There are two
approaches to deploying an image on a local Kubernetes cluster
1) Interactive
2) Declarative
In interactive approach, you have to give all of the Kubernetes deployment and orchestration steps
directly as commands with arguments. While as in declarative approach, you specify details in a
Kubernetes deployment manifest file and use that manifest as the parameters when running
Kubernetes.
Interactive example by running the following command:Hide Copy Code
kubectl run aks-deployment --image=aks:local --port=80 --replicas=3
The key option here is --replicas, which we use to specify that three replicas are needed for the
application. When command executed, a deployment is created where the desired state is set to three
replicas. A replica set is created that ensures that there are always three replicas of the application
running.
Then the scheduler schedules the pod deployment on the worker node, which commands to the docker
engine running on the worker node to pull the image and then run in pods.
Once the application is deployed, create a service to expose this deployment.
Hide Copy Code
kubectl expose deployment aks-deployment --type=NodePort
This creates the service. Verify it by running kubectl get service or kubectl get svc.
To connect to the service, launch the browser and connect to the localhost followed by the port number
exposed on the node. Now I have opened three browsers and hit the same URL.
You can see that the container hostname changes. That's because behind the servers, there are three
pods, or containers, which the service is load balancing the request to.
Now Clean up the deployment and service by deleting them with the delete command.
Hide Copy Code
kubectl delete deployment aks-deployment
Likewise we can do, delete the service as well.
Hide Copy Code
kubectl delete service aks-deployment
Declarative approach uses pre-configured options saved in a deployment manifest file. You can use from
YAML manifest file at the root of the application: aksdeploy.yml. The file has two divisions. The first
specifies how to create the deployment. The second specifies how to expose it as a service.
Step 1- Open the file and change the number of replicas ("replicas:") to 3, and the image file name
("image:") to aks:local.
Below command creates the deployment and service using the configuration in aksdeploy.yml.
Hide Copy Code
kubectl create -f .aksdeploy.yml
Step2- Check the status of the service using kubectl get svc and then launch a browser to connect
to the service. You will be able to see the same result as the previous interactive demo, with requests
spread across the available replicas.
Now you can again delete the deployment and the service, but this time by specifying the file name.
Hide Copy Code
kubectl delete -f .aksdeploy.yml
 Docker Image and Azure Container Registry (ACR)
The main part of user containers is having that readily available in a registry. So let’s push our Docker
image of the application to the Registry. For that we will follow the 9 steps in Azure CLI.
1- Log in to Azure using the az login command.
2- Create a resource group with the name as aksgroup and the location as australiaeast. (You can
use your own location here as appropriate.)
Hide Copy Code
az group create -n aksgroup -l australiaeast
3- Now create a container registry entry with the name learningaksacr, the resource group as
aksgroup, the location as australiaeast (or your preferred location), and the sku as standard.
Hide Copy Code
az acr create -n learningaksacr -g aksgroup --sku standard
4- Once the container registry is created, the image needs to be pushed. First, log in.
Hide Copy Code
az acr login -n learningaksacr
5- After successful login, before pushing, tag the local image with the login server name of the container
registry.
Hide Copy Code
az acr list -o table
Now you should keep noted the login server name with you.
6- To list the Docker images available on this machine, we can use the docker image list command. We
have the aks:local image, which needs to be tagged using the login server name.
7-Run the docker tag command. Specify the local image name, the new name (which is going to be the
login server name), and the image name and the tag.
Hide Copy Code
docker tag aks:local learningaksacr.azurecr.io/aks/v1
8- Verify this by docker image list command and we see the successfully tagged image. Both local and
tagged image share the same image ID.
9- To Register in ACR use the docker push command to push the tagged image to the registry.
Hide Copy Code
docker push learningaksacr.azurecr.io/aks/v1:latest
This image can now be used or accessed by any other Docker machine or the AKS cluster can easily pull
this image from the registry.
 Deploying Azure Kubernetes Service (AKS) Cluster
As of now we have deployed the Kubernetes cluster locally, now it’s time to deploy to Azure using AKS.
With AKS, a production-grade Kubernetes cluster could easily be provisioned.We need to create a
service principal, registering the application to Azure Active Directory (AD), and create an identity for it
before proceeding for this and registered ID is required if the application will expose itself to other Azure
services.
1-Create a service principal using the Azure CLI with the command:
Hide Copy Code
az ad sp create-for-rbac --skip-assignment
After created, you copy FYI this information like appID, displayName, URL, password, and tenant
properties for the service principal..
2- Give grant the permissions to the service principal to pull the images from the ACR. use PowerShell
window here.
Get the ACR resource ID ($acrId) using the az acr show command.
Hide Copy Code
az acr show --name learningaksacr --resource-group aksgroup --query "id"
3- Then grant the reader role to the AKS cluster so that it can read the images stored in ACR by using the
az role assignment create command.
Hide Copy Code
az role assignment create --assignee [appID] --role Reader -- scope $acrId
Use the appID that was provided for the service principal, and the scope is set to the resource ID of the
ACR, which was fetched from the az acr show command.
4- Next we have create our AKS cluster using the az aks create command. Provide a name and the
resource-group. For the node-count, make it a single worker node. Use the generate-ssh-keys to
generate the SSH public (and private) key files. Specify the service-principal and the client-
secret, which is the application ID and the password copied earlier. Run the command.
Hide Copy Code
az aks create `
>> --name learningakscluster `
>> --resource-group aksgroup
>> -- node-count 1 `
>> --generate-ssh-keys `
>> --service-principal [appID] `
>> --client-secret [password]
5- After the deployment is complete, and to connect to our AKS cluster from the client computer, use the
kubectlcommand-line interface.
The .kube file located at the user’s location as shown in the following image contains the server setting
set to a local server running on port 6445.
Get the credentials of our AKS cluster just deployed by using the az aks get-credentials
command, specifying the name and the resource-group name.
6- To check go back to the .kubeconfig and notice that server now reflects the AKS cluster running in
Azure. To verify, execute the kubectl get nodes command. We can see a single node worker
confirming the successful provisioning of our AKS cluster.
 Deploying the ASP.NET Core Application to AKS
Now we are come for The clusterwhich is all set for the application to be deployed into it now.
1- Open the aksdeploy.yml file that we looked at earlier at the root of the application.
Currently, the image is referring to a local Docker image. Let’s change it to refer to the image we pushed
to our Azure Container Registry. Instead of the "image:" property pointing to aks:local, change this to
the image name on the server with the tag: learningaksacr.azurecr.io/aks/v1:latest.
Previously , we had deployed this application to the local cluster and used the service type as NodePort.
2-Now that we're deploying those to a cloud service like Azure, we can change the "type:" property to
LoadBalancer
3-Save the file, then use the kubectl apply command for deployment.
Hide Copy Code
kubectl apply -f .aksdeploy.yml
This will create defined Kubernetes objects, which includes deployment and service. The service created
exposes the application to the internet.
4-So now we monitor the progress of the deployment. use the kubectl get service command with
the --watch argument.
Initially, the external IP of the AKS deployment service appears as pending. Once the external IP has
changed from pending to an IP address, copy the IP.
5-To test your application; browse to the external IP address.
Wow now our application is running on a worker node within an AKS cluster.
Take away: I hope you have understood how to containerize and deploy an ASP.NET Core
application -- or any similar micro service application-- to Azure Kubernetes Services and we also have
explored the role of Azure Container Registry in the article. Please feel free to like this and share in like-
minded community.
To learn more about using Kubernetes through Azure Kubernetes Services, start with the Introduction
to Azure Kubernetes Services (AKS) in the Microsoft Azure documentation. You should be familiar with
some of the steps after reading this article, but the documentation will walk you through additional options
and scenarios. Connect with Author: Ranjeet Bhargava He is an Azure Solution Architect.
Please get in touch him: https://www.linkedin.com/in/bhargavamcp/
Thanks for reading this article. Be in touch!!

More Related Content

What's hot

Deploy the blockchain network using kubernetes ap is on google cloud
Deploy the blockchain network using kubernetes ap is on google cloudDeploy the blockchain network using kubernetes ap is on google cloud
Deploy the blockchain network using kubernetes ap is on google cloudAjeet Singh
 
Docker : Container Virtualization
Docker : Container VirtualizationDocker : Container Virtualization
Docker : Container VirtualizationRanjan Baisak
 
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...Tobias Schneck
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaJadson Santos
 
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...Edureka!
 
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...Tobias Schneck
 
Cd with Github Travis CI and Heroku
Cd with Github Travis CI and HerokuCd with Github Travis CI and Heroku
Cd with Github Travis CI and HerokuJadson Santos
 
Ship your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerShip your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerMarcus Lönnberg
 
Docker for Fun and Profit
Docker for Fun and ProfitDocker for Fun and Profit
Docker for Fun and ProfitKel Cecil
 
Containerization and Docker
Containerization and DockerContainerization and Docker
Containerization and DockerMegha Bansal
 
Docker in practice
Docker in practiceDocker in practice
Docker in practiceGeert Pante
 
Docker Voting App Orientation
Docker Voting App OrientationDocker Voting App Orientation
Docker Voting App OrientationTony Pujals
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with dockerMichelle Liu
 
Containers and Kubernetes -Notes Leo
Containers and Kubernetes -Notes LeoContainers and Kubernetes -Notes Leo
Containers and Kubernetes -Notes LeoLéopold Gault
 
Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2Hao H. Zhang
 

What's hot (19)

Docker
DockerDocker
Docker
 
Deploy the blockchain network using kubernetes ap is on google cloud
Deploy the blockchain network using kubernetes ap is on google cloudDeploy the blockchain network using kubernetes ap is on google cloud
Deploy the blockchain network using kubernetes ap is on google cloud
 
Docker : Container Virtualization
Docker : Container VirtualizationDocker : Container Virtualization
Docker : Container Virtualization
 
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...Kubernetes Cluster API - managing the infrastructure of  multi clusters (k8s ...
Kubernetes Cluster API - managing the infrastructure of multi clusters (k8s ...
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and Java
 
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
Kubernetes Interview Questions And Answers | Kubernetes Tutorial | Kubernetes...
 
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
Kubermatic How to Migrate 100 Clusters from On-Prem to Google Cloud Without D...
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Cd with Github Travis CI and Heroku
Cd with Github Travis CI and HerokuCd with Github Travis CI and Heroku
Cd with Github Travis CI and Heroku
 
Dockerfile
Dockerfile Dockerfile
Dockerfile
 
Ship your Scala code often and easy with Docker
Ship your Scala code often and easy with DockerShip your Scala code often and easy with Docker
Ship your Scala code often and easy with Docker
 
Docker for Fun and Profit
Docker for Fun and ProfitDocker for Fun and Profit
Docker for Fun and Profit
 
Containerization and Docker
Containerization and DockerContainerization and Docker
Containerization and Docker
 
Docker in practice
Docker in practiceDocker in practice
Docker in practice
 
Docker Voting App Orientation
Docker Voting App OrientationDocker Voting App Orientation
Docker Voting App Orientation
 
Up and running with docker
Up and running with dockerUp and running with docker
Up and running with docker
 
Containers and Kubernetes -Notes Leo
Containers and Kubernetes -Notes LeoContainers and Kubernetes -Notes Leo
Containers and Kubernetes -Notes Leo
 
Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2Kubernetes Architecture - beyond a black box - Part 2
Kubernetes Architecture - beyond a black box - Part 2
 
Kayobe_desc
Kayobe_descKayobe_desc
Kayobe_desc
 

Similar to Dockerized .Net Core based app services in azure K8s

Build containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfBuild containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfHamida Rebai Trabelsi
 
Rome .NET Conference 2024 - Remote Conference
Rome .NET Conference 2024  - Remote ConferenceRome .NET Conference 2024  - Remote Conference
Rome .NET Conference 2024 - Remote ConferenceHamida Rebai Trabelsi
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platformnirajrules
 
Docker Basic to Advance
Docker Basic to AdvanceDocker Basic to Advance
Docker Basic to AdvanceParas Jain
 
What Is AWS Elastic Kubernetes Service
 What Is AWS Elastic Kubernetes Service What Is AWS Elastic Kubernetes Service
What Is AWS Elastic Kubernetes ServiceAMELIAOLIVIA2
 
Building a Kubernetes App with Amazon EKS
Building a Kubernetes App with Amazon EKSBuilding a Kubernetes App with Amazon EKS
Building a Kubernetes App with Amazon EKSDevOps.com
 
Build, Deploy and Run Node Js Application on Azure using Docker
Build, Deploy and Run Node Js Application on Azure using DockerBuild, Deploy and Run Node Js Application on Azure using Docker
Build, Deploy and Run Node Js Application on Azure using DockerOsama Mustafa
 
How to Dockerize Web Application using Docker Compose
How to Dockerize Web Application using Docker ComposeHow to Dockerize Web Application using Docker Compose
How to Dockerize Web Application using Docker ComposeEvoke Technologies
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSYevgeniy Brikman
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Binary Studio
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionPaolo latella
 
How to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialHow to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialKaty Slemon
 
Running your dockerized application(s) on AWS Elastic Container Service
Running your dockerized application(s) on AWS Elastic Container ServiceRunning your dockerized application(s) on AWS Elastic Container Service
Running your dockerized application(s) on AWS Elastic Container ServiceMarco Pas
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Docker, Inc.
 
Monitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
Monitoring Docker Containers with Metricbeat, Elasticsearch, and KibanaMonitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
Monitoring Docker Containers with Metricbeat, Elasticsearch, and KibanaQbox
 
B14870 solution final
B14870 solution finalB14870 solution final
B14870 solution finalssuser8f0495
 

Similar to Dockerized .Net Core based app services in azure K8s (20)

Build containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfBuild containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdf
 
Rome .NET Conference 2024 - Remote Conference
Rome .NET Conference 2024  - Remote ConferenceRome .NET Conference 2024  - Remote Conference
Rome .NET Conference 2024 - Remote Conference
 
Dockerization of Azure Platform
Dockerization of Azure PlatformDockerization of Azure Platform
Dockerization of Azure Platform
 
Docker Basic to Advance
Docker Basic to AdvanceDocker Basic to Advance
Docker Basic to Advance
 
What Is AWS Elastic Kubernetes Service
 What Is AWS Elastic Kubernetes Service What Is AWS Elastic Kubernetes Service
What Is AWS Elastic Kubernetes Service
 
Building a Kubernetes App with Amazon EKS
Building a Kubernetes App with Amazon EKSBuilding a Kubernetes App with Amazon EKS
Building a Kubernetes App with Amazon EKS
 
Build, Deploy and Run Node Js Application on Azure using Docker
Build, Deploy and Run Node Js Application on Azure using DockerBuild, Deploy and Run Node Js Application on Azure using Docker
Build, Deploy and Run Node Js Application on Azure using Docker
 
How to Dockerize Web Application using Docker Compose
How to Dockerize Web Application using Docker ComposeHow to Dockerize Web Application using Docker Compose
How to Dockerize Web Application using Docker Compose
 
Overview of Docker
Overview of DockerOverview of Docker
Overview of Docker
 
Docker for Developers
Docker for DevelopersDocker for Developers
Docker for Developers
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to production
 
How to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorialHow to dockerize rails application compose and rails tutorial
How to dockerize rails application compose and rails tutorial
 
Introduction To Docker
Introduction To  DockerIntroduction To  Docker
Introduction To Docker
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
Running your dockerized application(s) on AWS Elastic Container Service
Running your dockerized application(s) on AWS Elastic Container ServiceRunning your dockerized application(s) on AWS Elastic Container Service
Running your dockerized application(s) on AWS Elastic Container Service
 
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
Build, Publish, Deploy and Test Docker images and containers with Jenkins Wor...
 
Monitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
Monitoring Docker Containers with Metricbeat, Elasticsearch, and KibanaMonitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
Monitoring Docker Containers with Metricbeat, Elasticsearch, and Kibana
 
B14870 solution final
B14870 solution finalB14870 solution final
B14870 solution final
 

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Dockerized .Net Core based app services in azure K8s

  • 1. Dockerized .net core application with AK8s services ***Symbols are subject to copy right for Microsoft Develop .Net Core Application with Azure Kubernetesservices #AKS #Azure #AppsServise #CloudApps #Docker #.netCore Posted by Ranjeet Bhargava on August 02 2019. Now a day we are living in the hyper scaled digitalized world where everyone is connected direct or indirect - loosely or tightly with Apps or I can say Virtually Apps are surrounded with use all the time. Today I would like to share my experience on the Devops specific to the Dockers containers and Kubernetes with -Azure Apps Services -API Integrations for micro services architecture which evolved to boost up by solving problems and shortcomings of monolithic applications.
  • 2. Containerizations ref as Portable Containers (K8s) here - by Docker /Kubernetes platforms are now made faster and easy to bundle the applications’ packages & placing the deployments quickly.  Azure K8s platform helps us to create deployments, orchestrate the deployments on demand and manages applications under the hoods.  Microsoft’s Azure Kubernetes Services (AKS) is cloud hosting services which provide built-in Kubernetes services that help you to orchestrate cloud-hosted functions and microservices in their environment. So friends we will be engaged for just three practices ABC as below [.Net Core Application] a) 1st we will create one ASP.NET Core web application. b) 2nd we will containerize this application with Docker. c) 3rd we will deploy this on AKS cluster. Please don’t worry about the functionalities of this application as we’ll use it for the deployment only that can explain where it’s running and it is scaled. Our focus would be on creating the containers and using Kubernetes to deploy the application to an AKS cluster. When the application is dockerized, we’ll create a local image of the application to test locally. Pre-Requisite 1. Git for Windows 2. .NET Core 2.1 or above 3. Azure CLI 4. Azure PowerShell 5. Docker for Windows Click to Install Docker We will require a valid Azure account for the deployment, and we’ll be using the following applications on the development machine. When docker for Windows is installed and running, then goes to the settings and enable the checkbox for Kubernetes as shown below:
  • 3. If in your environment is docker for Windows should be running in Linux container mode, otherwise, the Kubernetes option will not be shown in the settings. Then do the Azure CLI installation, run the following command (az --version) to make sure the CLI is up and running. Now you should clone or download the code from below Git Repository project: https://bhargavaonline.visualstudio.com/AKS%20with%20ASP.Net%20Core%20Application
  • 4.  Application Setups: Next step after cloned or downloaded and unzipped, execute the dotnet run command as shown below. This will run the server and tell on what port the server is listening for the application, i.e., http://localhost:5000. You can follow these steps with Applications which you might be created at your end. Now open the browser and try http://localhost:5000. Check it’s just a simple application showing the host or container in which the application is running. Currently, it runs on a development windows machine without a container and so it shows the name of the host machine, in this case 3593BH2.
  • 5.  Setting Docker [Container] We will use Docker to create a container for the application. Alternately you can download the sample code. After creating container Navigate to the root of the application directory to see the already created docker file. This Dicker’s file will be used to build the image. The runtime image is built using the docker build command as shown below: Hide Copy Code docker build . -t aks:local Make sure that you are in the directory that contains a Docker file and then run the command. If you’re not familiar with the syntax, the dot indicates that the Docker file is located in the current directory and the -t switch allows you to specify the tag aks:local. This kicked start the build process. Once the build completes, run the docker image list command. It lists a brand-new image called aks:local.
  • 6. To test this image, run a container based on this image by using the docker run command: Hide Copy Code docker run -d -p 5000:80 aks:local The -d switch tells Docker to run this as a daemon process. The -p switch maps port 5000 on the host to local port 80 on the container. Execute command docker ps to see the container up and running. Now go to the browser and connect to http://localhost:5000. We see the application now running under docker container as the hostname now shows the ID of the container here. Delete the newly created test container by running:
  • 7. Hide Copy Code docker container rm -f [container name] For [container name], substitute the ID of the container as displayed in your browser or by running the docker ps command.  Deploy on a Local Kubernetes Cluster So now, we have to quickly deploy the application to a local Kubernetes cluster to illustrate the manual approach to orchestration with Kubernetes. This will provide a baseline to compare with Kubernetes orchestration with AKS. There are two approaches to deploying an image on a local Kubernetes cluster 1) Interactive 2) Declarative In interactive approach, you have to give all of the Kubernetes deployment and orchestration steps directly as commands with arguments. While as in declarative approach, you specify details in a Kubernetes deployment manifest file and use that manifest as the parameters when running Kubernetes. Interactive example by running the following command:Hide Copy Code kubectl run aks-deployment --image=aks:local --port=80 --replicas=3 The key option here is --replicas, which we use to specify that three replicas are needed for the application. When command executed, a deployment is created where the desired state is set to three replicas. A replica set is created that ensures that there are always three replicas of the application running. Then the scheduler schedules the pod deployment on the worker node, which commands to the docker engine running on the worker node to pull the image and then run in pods.
  • 8. Once the application is deployed, create a service to expose this deployment. Hide Copy Code kubectl expose deployment aks-deployment --type=NodePort This creates the service. Verify it by running kubectl get service or kubectl get svc. To connect to the service, launch the browser and connect to the localhost followed by the port number exposed on the node. Now I have opened three browsers and hit the same URL.
  • 9. You can see that the container hostname changes. That's because behind the servers, there are three pods, or containers, which the service is load balancing the request to. Now Clean up the deployment and service by deleting them with the delete command. Hide Copy Code kubectl delete deployment aks-deployment Likewise we can do, delete the service as well. Hide Copy Code kubectl delete service aks-deployment
  • 10. Declarative approach uses pre-configured options saved in a deployment manifest file. You can use from YAML manifest file at the root of the application: aksdeploy.yml. The file has two divisions. The first specifies how to create the deployment. The second specifies how to expose it as a service. Step 1- Open the file and change the number of replicas ("replicas:") to 3, and the image file name ("image:") to aks:local. Below command creates the deployment and service using the configuration in aksdeploy.yml. Hide Copy Code kubectl create -f .aksdeploy.yml Step2- Check the status of the service using kubectl get svc and then launch a browser to connect to the service. You will be able to see the same result as the previous interactive demo, with requests spread across the available replicas. Now you can again delete the deployment and the service, but this time by specifying the file name. Hide Copy Code kubectl delete -f .aksdeploy.yml
  • 11.  Docker Image and Azure Container Registry (ACR) The main part of user containers is having that readily available in a registry. So let’s push our Docker image of the application to the Registry. For that we will follow the 9 steps in Azure CLI. 1- Log in to Azure using the az login command. 2- Create a resource group with the name as aksgroup and the location as australiaeast. (You can use your own location here as appropriate.) Hide Copy Code az group create -n aksgroup -l australiaeast 3- Now create a container registry entry with the name learningaksacr, the resource group as aksgroup, the location as australiaeast (or your preferred location), and the sku as standard. Hide Copy Code az acr create -n learningaksacr -g aksgroup --sku standard 4- Once the container registry is created, the image needs to be pushed. First, log in. Hide Copy Code az acr login -n learningaksacr 5- After successful login, before pushing, tag the local image with the login server name of the container registry. Hide Copy Code az acr list -o table Now you should keep noted the login server name with you. 6- To list the Docker images available on this machine, we can use the docker image list command. We have the aks:local image, which needs to be tagged using the login server name.
  • 12. 7-Run the docker tag command. Specify the local image name, the new name (which is going to be the login server name), and the image name and the tag. Hide Copy Code docker tag aks:local learningaksacr.azurecr.io/aks/v1 8- Verify this by docker image list command and we see the successfully tagged image. Both local and tagged image share the same image ID. 9- To Register in ACR use the docker push command to push the tagged image to the registry. Hide Copy Code docker push learningaksacr.azurecr.io/aks/v1:latest This image can now be used or accessed by any other Docker machine or the AKS cluster can easily pull this image from the registry.
  • 13.  Deploying Azure Kubernetes Service (AKS) Cluster As of now we have deployed the Kubernetes cluster locally, now it’s time to deploy to Azure using AKS. With AKS, a production-grade Kubernetes cluster could easily be provisioned.We need to create a service principal, registering the application to Azure Active Directory (AD), and create an identity for it before proceeding for this and registered ID is required if the application will expose itself to other Azure services. 1-Create a service principal using the Azure CLI with the command: Hide Copy Code az ad sp create-for-rbac --skip-assignment After created, you copy FYI this information like appID, displayName, URL, password, and tenant properties for the service principal.. 2- Give grant the permissions to the service principal to pull the images from the ACR. use PowerShell window here. Get the ACR resource ID ($acrId) using the az acr show command. Hide Copy Code az acr show --name learningaksacr --resource-group aksgroup --query "id" 3- Then grant the reader role to the AKS cluster so that it can read the images stored in ACR by using the az role assignment create command. Hide Copy Code az role assignment create --assignee [appID] --role Reader -- scope $acrId Use the appID that was provided for the service principal, and the scope is set to the resource ID of the ACR, which was fetched from the az acr show command. 4- Next we have create our AKS cluster using the az aks create command. Provide a name and the resource-group. For the node-count, make it a single worker node. Use the generate-ssh-keys to generate the SSH public (and private) key files. Specify the service-principal and the client- secret, which is the application ID and the password copied earlier. Run the command. Hide Copy Code az aks create ` >> --name learningakscluster ` >> --resource-group aksgroup >> -- node-count 1 ` >> --generate-ssh-keys ` >> --service-principal [appID] ` >> --client-secret [password] 5- After the deployment is complete, and to connect to our AKS cluster from the client computer, use the kubectlcommand-line interface.
  • 14. The .kube file located at the user’s location as shown in the following image contains the server setting set to a local server running on port 6445. Get the credentials of our AKS cluster just deployed by using the az aks get-credentials command, specifying the name and the resource-group name. 6- To check go back to the .kubeconfig and notice that server now reflects the AKS cluster running in Azure. To verify, execute the kubectl get nodes command. We can see a single node worker confirming the successful provisioning of our AKS cluster.
  • 15.  Deploying the ASP.NET Core Application to AKS Now we are come for The clusterwhich is all set for the application to be deployed into it now. 1- Open the aksdeploy.yml file that we looked at earlier at the root of the application. Currently, the image is referring to a local Docker image. Let’s change it to refer to the image we pushed to our Azure Container Registry. Instead of the "image:" property pointing to aks:local, change this to the image name on the server with the tag: learningaksacr.azurecr.io/aks/v1:latest. Previously , we had deployed this application to the local cluster and used the service type as NodePort. 2-Now that we're deploying those to a cloud service like Azure, we can change the "type:" property to LoadBalancer 3-Save the file, then use the kubectl apply command for deployment. Hide Copy Code kubectl apply -f .aksdeploy.yml This will create defined Kubernetes objects, which includes deployment and service. The service created exposes the application to the internet.
  • 16. 4-So now we monitor the progress of the deployment. use the kubectl get service command with the --watch argument. Initially, the external IP of the AKS deployment service appears as pending. Once the external IP has changed from pending to an IP address, copy the IP. 5-To test your application; browse to the external IP address. Wow now our application is running on a worker node within an AKS cluster. Take away: I hope you have understood how to containerize and deploy an ASP.NET Core application -- or any similar micro service application-- to Azure Kubernetes Services and we also have explored the role of Azure Container Registry in the article. Please feel free to like this and share in like- minded community. To learn more about using Kubernetes through Azure Kubernetes Services, start with the Introduction to Azure Kubernetes Services (AKS) in the Microsoft Azure documentation. You should be familiar with some of the steps after reading this article, but the documentation will walk you through additional options and scenarios. Connect with Author: Ranjeet Bhargava He is an Azure Solution Architect. Please get in touch him: https://www.linkedin.com/in/bhargavamcp/ Thanks for reading this article. Be in touch!!