ASP.NET Web application deployment on Azure Kubernetes Services through Azure DevOps CI/CD | AKS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello all and welcome to my channel devopsmela so guys in this video tutorial we'll talk about how do we deploy asp.net web application on azure kubernetes using azure devops ci cd pipeline okay before before i go ahead and proceed further uh i will i would like to call of some name like raghu charu sridhar and kelas and there are many more who have put down who have taken time to put down in comment that this is what they're looking for next okay so i just want to tell you guys i'm reading through your comments if you're giving a feedback and if it is visible for me i will definitely make a video on it okay and plus i have conducted a survey like a pool in between whether i should make a a kc icd video or should i make a aws devops end-to-end video so there was a 50-50 percent votes which i got for 50 i got for aks fifty percent i got for aws devops so guys i will be making videos on both the topics now so yeah here we go uh this is a video a complete end to end a kubernetes service video wherein i'll be deploying a dotnet application on kubernetes and even i'm making a video on azure aws devops wherein uh i'll be covering the complete aws devops and one of my video needleworks devops is already there on my channel you can look for code commit video it's end-to-end code comment video and slowly and steadily i'm coming up with code build code release and all the other topics of aws develop so guys if you're new to this channel please subscribe because there are so many videos lined up right now and if you have already subscribed please put down in your comment there are various ways you can send send me your feedback you can put it in the comment box uh you can write an email to me on devopsmail at gmail or you can even visit my website and you can you can just simply go on you can visit this devopsmail.com and over here there's option you can send me a feedback from here too okay so there are various options you can you can go ahead and look for the option and this is my website wherein i put in all the latest videos so you can go and check this website also okay so so the agenda is will be creating a dotnet application and will deploy that.net application on azure kubernetes services and will be using azure ci cd so this will be completely automated process okay so if and there are there are a few prerequisites there are few prerequisites which you have to take care before even coming to this screen like you need to set up a acr that's a container registry if i just i'm i'm on portal right now so if i go in my container registry i already have a container registry set up okay and i already have one single node aks cluster setup so if i go in my container registry this is my container registry so if you go in my container registry i don't have any image right now so it's a completely blank let's wait it's taking a bit of time so there's no image right now and if you go in my kubernetes services i have a single node kubernetes cluster okay so i have a single node combinative cluster uh which is running right now so these are the two things uh which you need to go ahead and pre-set up okay now if you guys are not familiar how exactly these are done because this will be completely automated we'll be having a multiple script and the scripts would be running through our ci cd pipeline and things will be deployed very quickly but if you're not aware how basically if you want to do all this thing manually how exactly that is done okay so if you're not aware if you're not familiar with it so go back to my channel i have a complete series on asp.net application wherein i am creating a image out of a docker file how the docker file is written how how that image gets like pushed into an acr and from acr how the email like through through that image how do we create a how we deploy that application on aks everything is there just look for devops mail as a site in the search box devopsmailer asp.net it will take you to this series asp.net code deployment series so if you go inside it you will see all the information like i have covered how do we create a image and how do we push that image in acr how do we create a aks cluster and how do we push image like from acr how do we pick that image from the acr and deploy it on aks see all manual everything is manual so you can go and look at this playlist and you will understand how exactly things are done manual first okay then you can come come back to this new video which i am creating wherein i am deploying things on using ci cd pipeline so if you understand manual well encode you can directly jump out and jump on to this video and if you have never done if you never touch based how things are done manual first well look look look into that series video then you will come to then you'll understand each and every step okay so that's it let's go ahead and start with this video now okay guys let's understand the flow uh what exactly we're gonna do in this tutorial video so firstly uh we need a asp.net web application so i already have a web application created it's a simple web application it's just displaying welcome to devops mail on the screen when this thing will get deployed on your case okay and next uh we need a docker file so docker file is needed for creating an image out of build so this is the docker file what we have so if i just walk you through this docker file in the first line i uh it's the sdk microsoft.sdk i'm creating a directory all this step will be done inside my agent pool when we'll run through a ci pipeline okay these are all automated if you are new and if you want to know how exactly this was created please check my asp.net series i have done this manual over there okay you'll understand more okay let me walk you through the steps uh we are creating a directory uh slash app copying all our sample web app so it's the complete project the project name is simple web app copying the complete project file the cs proj file into the current directory then we are running the dotnet restore command okay now over here we are copying the web app and putting it in again into a complete into the current directory from here we are running a dotnet publish command and over here we are getting an output web app this is an output which is getting created so these are my build process okay and i have a flag no restore because i've already done a restore at this step okay now on these we are creating an image okay so this is a working directory again web app this is something which output was created we are copying the build from web app to this directory and we are running the uh application entrypoint.net sample webapp.dl so this is my docker file using this docker file my build and my image would be created and post that will be pushing that image into an acr so we already have acr created this is the container registry which is created and then post that will deploy into our aks cluster that's your kubernetes cluster in order to deploy we need two files okay we need a deployment.yaml file and we need a service.yml file so using a service file we can access that application from outside from outside world and deployment.aml file will deploy the application for me so if you see that this is the name of my application and it's getting the image from a devops across check my container registry i don't have any image inside it if i just go in repositories i have no image but once the build pipeline is successful our image will get created over here okay and we are opening a port 80 away so all these files are pre-created if i just go and show you my application structure this is my application sample web app i have my app and inside this app a folder i have my docker file okay and i have a folder created manifest inside my manifest i have my deployment.yaml and service.tml i even have a azure pipeline.yaml file created okay don't worry this is something we'll be recreating just for this demo i'll be deleting this file from my repository remote repository and i'll be just recreating this entire thing for you okay so this is my fly this is how the file structure looks i think that's it from here now let's go back on azure ci cd this is my repository so the things already pushed in my remote repository so don't worry guys i will put i will be putting the complete uh scripts and everything into my github okay it's mentioned in my description you can go and refer to this application you can get all this deployment.aml and ml and docker file from there and you can use it okay so it will be there in my github repository uh you can check the description box for the link okay coming back this is my repository so if you see in my repository i don't have a yaml file so it's already deleted we'll be creating everything from scratch okay the first thing first we'll go in pipelines and in pipelines i'll be creating a new pipeline okay in the new pipeline uh i'll be creating a yaml so definitely yes not a classic yaml one so i'll select my as my repository is in azure repos i'm selecting azure repos uh the name of the repository is simple web app so this is what i'm selecting right now so the simple web app it is automatically detecting that i have uh and dotnet application and things okay now over here i'm getting an option of build and push image to azure container registry deployed to azure kubernetes services so these uh if i select the this option uh the azure aml file will be created okay automatically let's go and make use of this default template and we will go and make changes to that we'll understand each and every line what exactly that template is doing what all what all tasks the template is running so let's let's do this okay now when when i click on it it will look for my subscription okay so it will connect it will create a service connection between my azure devops and azure cloud because we are using two services of azure cloud we're using aks so we need a service connection created between devops to connect to aks and even when we are connecting to acr that's azure container registry so even we need service connection for that too so if i go back in my project settings i don't have any service connection created right now for aks or even for the acr okay so i'll show you how automatically the service connection will be created because of this okay if you guys are not aware what exactly service connection is how do we create a service connection manually please do check i have a service connection video as well so wherein i have walked through how to create a service connection manually or how to create a service connection automatically okay go and have a check okay now select my subscription this is a subscription if you go back this is the subscription which i'm using devops mailer training so i have selected the subscription that is the only subscription i have i will just login gmail so if you have not subscribed please subscribe to my channel okay let me sign in okay guys i'm signed in now i'll select the cluster name as a uh devops melee so this is already created i have a namespace i'll be using this existing default space so if you want to create a new one you can select the new option i'll i'll stick to default namespace and i have a container registry as well so devopsmedia acr is a container registry this is the image name which will be created and we're enabling the port 80 okay i'll go ahead and validate and configure the template so what will happen a ml file would be created automatically with all the options okay so let's wait while the ml file is getting created and while the ml file is getting generated okay in the mean so it's creating a yaml file as well as it is creating a service connection in the packet okay so we are referring to so if i go back to my service connection if i just refresh it so i should have a service connection created for aks and even a service connection created for a container registry so both are created now coming back to new pipelines so let me walk you through what all things and what all uh tasks we have in this yaml firstly we have the trigger so we have uh we have a trigger set on main so if there is any change uh happening on this main branch again then this pipeline will not to trigger repo itself because we are creating the cml file inside this con main branch so in inside this main branch even this ml will be created that is what that step is okay we have multiple variables defined so if you go and look into the variables i have uh docker registry service connection id i have image repository i have my container registry so all these variables will be calling these these variables in a task what we have done i have my docker file path so if you go and see i have this docker file inside my app okay so i have this dockerfile right placed over here okay and i have a tag so we are doing a tagging with with the build id and this is the image pull secret file secret which is getting created we are using a agent pool on this step we're using a agent tool ubuntu latest it will take the latest ubuntu machine as my agent tool and there are multi-stage there are multiple stages what i have in my yaml file the first stage is to build wherein we are building an application then we are pushing that application into an acr so this is the stage which we are on to so if you see this again i have agent pool over here so if if you see this task the first task what we have this task so i'm creating a build and pushing an image to a container registry the command is build and push this is the command which we are running we are referring to this image repository so if you go into image repository this is where we are referring sample web app then we are referring to the uh docker file path it will go and look into my docker file these are the steps which will which which will run okay then we have a container registry so again at the end it is pushing the changes to my container docker registry service connection okay so this is the service connection it is referring to the service connection over here okay now and we are tagging it with the name tag so tag we are getting it from the build id so we're getting the build id based on that we're getting the tags okay post that on the step 44 and 45 we are creating a manifest file and in the manifest file we are pushing all the changes okay so artifact would be created that artifact will contain uh the deployment.aml and it will contain the service.ml file okay now but if you highlight on this so you're getting a warning this option is depreciated use publish insist so i can do one thing i can just remove it and i'll just using this show assistance i will run one task called copy we already have a file correct we already have a manifest file created so i want this manifest file to be copied as a artifact and when my aks deployment task is running i want these manifest file to run okay how exactly we can do it i will just run a copy copy file command file so my source is manifest okay contain what i want to copy i want to copy all the aml files okay so let me put it this way i can put it this way dml so everything inside this for folder if you have a yaml file only the ml file will get copied as if now we just have yaml so this way you can put it or you can even put it this way even that both works okay target folder where exactly i want to copy if you come down in my script if you see this from where it is referring it is referring from the pipeline dot workspace so this becomes my target okay i want to copy this all over here okay so what exactly this pipeline workspace is so it's a predefined variable so the pipeline workspace is nothing but it's a local path on the agent where all folders for a given build pipelines are created okay that's a local path okay so i'll just put the target folder as well and i'll keep it as manifest okay so i'll just make sure it comes click over here and i'll make sure we are putting it on the right location here we go so what we are doing we are copying the manifest all the yaml files and we are putting into it the target folder okay this way my aks will be able to get this file when we are running the deploy okay plus we are using our own yaml files because we have already created a yaml so we are making use of our own email file okay we can even add a publish task wherein we can uh uh publish all the am like what what exactly we are running and if you want to have a look we can have a publish task and we can we can add a publish task and we can add all the cml files over there also so we'll come to know what exactly we are publishing so it is publish okay so you can look for this option publish pipeline artifact okay so automatically it is taking from here okay and artifact name you can give we can just give the same name as manifest okay and a manifest folder would be created so from this path okay to be very specific i'll just give this path also i can give this path also and i'm just placing whatever we have inside this file this folder it will be placed into this location okay this is nothing but its artifact published location from where we can a pipeline the release pipeline can even access the files okay so let me put it over here coming man just put it in just below the task only task what we have created okay so this is looking good let's verify for my local yaml what i have okay looks good okay that's it so these are the two tasks what we have added we have added a copy task we are copying all the files from the manifest folder and we are putting at this target location and from that target location i'm uploading everything in the manifest folder so this manifest folder which you are seeing over here there once the build is successful will have access to this manifest folder okay so this is uh this is about your build task what we are running let's come and see the deploy task now so in my deploy task again if you see i'm calling it we are using agent so we have mentioned the ubuntu agent at the very top so that is what we are calling it now we we're pulling the image from the acr we are pulling the image in this task we're pulling the image from the acr okay and from there once the image is pulled we are running the kubernetes cluster deploy action so if you see we are deploying things on kubernetes cluster this is the accent deploy and what exactly it is looking for if you see this it is looking for the deployment.yaml file first then it the second file it is looking for service.yaml file and in the next step we have we are pulling up the image secrets which we have mentioned at the very top in the variable and then okay that's it from the deploy task as well wherein we are pulling the image first from the acr and post that we are deploying the application on aks using these two files the deployment.tml and service.dml files okay let me quickly save this for now and i'm committing it to my main branch done this is the name let me change it let me give a good name likes web app build and deploy okay let me quickly run this and see what happens okay so my build stage has started so till now we don't have any registry inside my registry there is no repository created see no result let's let's wait while the build stage is running it may take around one minute not more it should not take more than that if you see that the checkout uh so over here it's checking out all my all my source code from my git repository azure repos repository now the actual build and push has started and if you see it is reading out my docker file and it is running all the steps mentioned inside my dockerfile let's wait while this gets over okay let me come back once the build is over okay guys so the build was successful if you see there's a one artifact got created even the copy type a task which we were running that was successful and even the artifact was published okay let's go and check out this build first if you see one artifact were created so let me see what all things we have in this so this was a folder which we have created manifest inside this we have a deployment.tml and service.ml this is what we needed correct let's go back to pipelines and my deployment task is pending right now and i need to go and approve it in order in order to deploy so let's wait while we go through this build first okay so this is my build build stage the build stage was successful and i got the artifact created now let's go in the deployment stage and let's approve it so that the deployment happens and before that let me refresh this repository okay before the deployment there are multiple things again okay we have a sample web app created repository created with the name simple web app and because of the tagging we got this 137 tag this is the image repository which we have in inside our container registry okay now before that i went to go on aks and we need to access this aks also correct so i'll be accessing using the cloud shell what i have over here i'll click on this cloud shell there are two things guys which you need to do with do two commands in short which you need to run to connect your aks cluster using a cloud shell the first command you need to run to install cube ctl so the command which is the cube ctl version all this command which i'm running you need to set up this okay you need to install cubectl so how exactly you'll do it i have that command in my notepad so this is the command which you need to run first so once once you run this you'll have cubectl installed so if you see this i have cube ctl installed over here okay second command is to uh allow cube ctel to connect to kubernetes cluster so this is the command which this will help you to connect to the kubernetes cluster okay without this two command you cannot connect to aks from the command line okay so run this to command i'll have this complete commands in my description as well as in my git repository you can get go go ahead and have a look over there okay let's see if the command is working or not so cube ctl get nodes so as i said i have a single node cluster so yeah this is ready let me see if i have any pods running or not okay there's no pod in the default name space so let's keep a watch so as soon as the pod gets created we'll see it over you okay let me permit this now permission granted the deployment has started let's wait it's waiting for an agent pool right now let's wait again it will take around okay it started the initialization started we started the download downloading the artifacts now it started creating a pull request it was done now we are running the actual task wherein we are deploying the application on a kubernetes cluster now if you see this see we get we're seeing the change a container is getting created okay let's wait while this is over then we'll go and check so if you see the service sample lab external ip was also assigned okay now if you come back over here this was a cluster created and there was external ip which was assigned this was the ip which was assigned and port 80 and this is the name of my web app so things looking pretty good over here let me cancel this now and let me run the get ports command again here we go we have a running pot if i want to describe it to see more details about the pod fctl describe command port simply copy this okay get more information about your container id more importantly the the port 80 and if you see created container simple web app started container sample web app and if you see from where it has pulled the image the devops melee acr is your cr dot io simple web app this is the place and the id 137 so this is what we have correct now if i just want to go and look the service cube ctl get service so you'll see the public ip as well so this was this uh service load balancer what we have created and that the name is sample web app this is external ip if i just copy this external ip and if i look it into any cognitive mode i'll see my web app let's see if it's working or not very good so this is my web application welcome to the box mela okay so guys this is how you come deploy an application a dotnet application on azure kubernetes services so there are various things various factors various scripts we have used in order to automate this entirely okay now just go through it and i'll be uploading each and everything in my description and my github repository just go through it and let me know if you have any questions just put down in the comment box and if you have not subscribed please do subscribe to my channel thank you bye you
Info
Channel: DevOps Mela
Views: 24,952
Rating: undefined out of 5
Keywords: Azure, AKS, Kubernetes, AzureKS, DevOps, ASP.NET, DockerFile, Yaml, Automation, AKS Deployment, Azure Kubernetes, CI/CD, Azure CI/CD, aks, Azure DevOps, Kubectl
Id: HmajgZEyYa8
Channel Id: undefined
Length: 31min 44sec (1904 seconds)
Published: Sat Dec 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.