How to create AKS Cluster and Deploy Springboot Microservices into AKS Cluster using Azure Pipeline

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back what we are going to learn in this video is how to create aks cluster in azure cloud and once the aks cluster is set up how to deploy spring boot application into a case cluster by building azure pipeline it's a very simple use case we are going to learn how to set up the aks cluster in azure cloud once the cluster is set up we will be deploying spring boot application into aks cluster using azure pipeline awesome so let's quickly go over the agenda as part of the prerequisites yes we need to have a case cluster setup and we will learn how to do that in a minute and then we need to have a spring boot application along with a docker file and kubernetes manifest file so i do have them over here so this is the sample spring boot application i have a docker file which we are going to use to create the docker image and then i do have kubernetes manifest file which we are going to use for deploying into aks cluster we will discuss about this file as we move along in the video all right so what we are going to do as part of the demo we are going to create the aks cluster using azure cli and then we will also create acropo in azure cloud so this is used for storing the docker image and then we will verify the kubernetes manifest file entry before deployment because um whatever the ecr entry you have sorry whatever the acr entry you have we need to modify this file right and this is the that docker image tag right so everything has to be in order before we can start deploying and then we will create a bill pipeline which is going to check out the code build the docker image and then upload the docker image into acr and then we will also create release pipeline which is going to deploy that docker image a docker container into aks cluster and finally we are going to access the spring boot application just to verify you know everything is working fine or not okay awesome so let's get started this is my website coachdevops.com i will be posting the link right below the video as well okay so let's look at this use case in detail so this is the springboot app what i talked about so we have already stored this in github it is available in github we also have a docker file we already saw that we have a sample kubernetes manifest file as well right and then we are going to build azure pipeline which is going to check out from github and we are going to do a maven build because if you look at the docker image we need to have jar file created right so we are going to build that using maven and then we are going to build the docker image we are going to tag it and then push the docker image into azure container registry and then finally we are going to create a release pipeline which is going to download the image from here and then deploy into docker container for that we are going to use kubernetes manifest file we're going to use this one okay so very simple use case spring boot application checked in into github we are creating azure bill pipeline to check out the code build the docker image upload the docker image into acr and then we will create release pipeline which is going to deploy the docker container or docker image into aks cluster awesome so let's get started so if you look at the prerequisites yes we do need to have a case cluster setup so if you look at here there are many ways you can create cluster okay so you can directly go into azure portal and create a case cluster or you can create a case cluster using azure cli command or you can also create a case cluster using terraform as well but i'm going to go with the simplest option which is to use azure cli and we will talk about that in a minute and then if you look at other prerequisites here right we also need to have acr so we will also do that in a minute and then we need to have access to azure devops dashboard so i do have my microsoft account setup which is actually not here which is which is here right so this is my azure devops dashboard and then we already talked about the docker file and then we need to make sure aks has full access from acr so that you know aks can download the docker image from acr during the deployment and then we will we will modify this entry as well right so we will cover one by one okay awesome so let's first create the cluster so like i said i'm going to go ahead with a cla option you can also learn other different ways as well so if you actually go to my channel so this is my channel home page so click on the search box and then if you type aks and then enter it's going to show you different ways of creating aks cluster but i'm going to pick up the one which is using azure cli okay so this is what i'm going to do so so this is the instruction for that the reason why i have chosen this is you know it's like one command just like one single command which is actually going to create the cluster for you right so so that's the reason why i'm going to go with this option for this particular demo awesome so let's get started so let me open up my item here so first of all we need to log into azure okay but before that we need to make sure we do have azure cli install i do have azure cli and you can verify that by entering this command so i do have azure cli install okay so let's first login into azure portal okay so this confirms that i have logged into azure cloud once you select your user credential perfect and then let's go ahead and create this resource group because as you know anything you create in azure cloud it has to be part of a resource group so first i want to create the resource group and i would like to use south central us so let's go ahead and then create the resource group there we go so resource group got created and then we can go ahead and then create aks cluster with two worker node okay again it is up to you you can create as many you want so i want to create a cluster this is a cluster name with two worker node and then yes i also want to enable monitoring and then generate ssh keys as well so let's copy this command so let's go ahead and then create aks cluster so this may take three to four minutes depending on the internet speed so i'm going to pause the video and then come back all right so the cluster got created and if you like to know the details of the cluster so we can use this command aks show command so this will give us some information in the command line and if you like to see it in the azure portal we can actually go there click on resource groups so this is the resource group what we created there you go you see here so this is the cluster name right and if you like to see how many nodes are there we can click on node pools there you go nodes there you go you see here so we have two worker nodes here perfect very good so let's continue and we also need to create acr as well this is where we are going to go ahead and then store the docker image so let me clear the screen so let's copy this make sure the acr name is unique otherwise you know it is not going to create awesome so right now the ac are also created perfect and then we should be able to see that over here as well we go to resource group let me refresh it might take couple of seconds there we go you see here so this is the container registry what we just created perfect very good so now what we are going to do we need to update the cube config the way we are going to update that is by executing this command so if you see here as you can see the cube config has been updated okay perfect so now what we should be able to do we should be able to uh perform cube ctl command so let me go ahead and then say get nodes so this should give me the worker node perfect and then if you like to look at how many namespaces are there so these are like you know the namespaces available for our aks cluster perfect and then if you want to deploy anything uh let's say if you want to deploy any um like nginx or anything like that you know you should be able to deploy that's pretty straightforward but before that let's go ahead and then um update our aks cluster so that you know we should be able to attach the acr right because what we need to do we need to give acr full access for our aks cluster okay so let's go ahead and then perform this command so this is going to update our cluster so this is the cluster name what we created and this is the resource group name and this is the acr what we just created so let's copy this command there are many ways you can give permission to your aks cluster in order to download the image but you know we would like to do this way okay this might take a few seconds let's see okay so that activity is done perfect so let's go ahead and clear the screen great so we set up the aks cluster we created acr we also gave pull access to a case cluster to download image from acr so everything is looking good and then our worker notes are running perfect uh i mean if you want you can go ahead and then deploy this nginx app but you know i'm going to skip that step okay perfect so let's get back to our original uh page here so we took care of this we also took care of this as well so now what we can do is we can go ahead and then create a pipeline right we can go ahead and then create a pipeline uh especially the azure build pipeline for building the docker image and then uploading the docker image into acr perfect so let's get started so i'm going to go back to my project dashboard so click on pipelines and click on new pipeline so we are going to go with the classic option okay of course you can also build a pipeline using ammo code as well i'm planning to put that video you know in a week or two but let's go with the classic editor our project is set up in github so make sure you already established connectivity between github and azure devops okay if you see here i have already established so i'm going to click on these three dots and i'm going to there we go so this is the repository click on springboard app and then select and then this is the branch i would like to use so click on continue so now what we are going to do we are going to choose the template because the goal of this build pipeline is to build the docker image and then upload the docker image into acr right so if you see here this is what we are actually going to use right or you can also type when you look for docker look at that so this is exactly what we wanted to do right so we want to choose this particular template so click on apply awesome you see here now now the pipeline got created okay and then if you want to choose the agent you can choose any any one of the agents let me go with the ubuntu latest okay so now we are going to start customizing our pipeline okay but before that let me first name the pipeline here uh rename the pipeline i'm going to say my awesome springboard ci pipeline okay perfect all right let me save don't say cube because we need to add a few other stuff so i just saved it okay perfect so now uh so these are the two tasks right you know it like pre-populated okay but if you see uh we need to have a task to build a jar file isn't it so i'm going to click on this plus i'm going to add a task search for maven and then i'm going to select this one okay sorry this should be here i'm going to move this to the top you need to build the jar file before you can you know build the docker image okay and then i'm going to click on the three dot if you see here uh our palm.xml file resides yeah i think it is in the root of the directory so you don't have to worry about that if you go here there you go you see here so i'm fine with that so this is fine and then gold is also fine you can do clean installer package that is also fine perfect so that's it over there and then let's let's add here let's modify this task so we need to provide azure container register information so let me click on azure subscription okay so i'm gonna go with this one okay um first time when you do it it may ask you to enter your microsoft credential if it asks go ahead and provide that i'm going to say something like this see when you choose like this it will ask you to click on this option it will ask you to enter your microsoft credentials when you do for the very first time right i have already done it but i'm just showing you again and then i'm gonna say approve from my authenticator app okay so this already exists that's fine so that's why i got that error but i'm going to go with one of the options okay perfect and then let's go ahead and then enter or select our acr information there you go you see here so this actually comes from azure portal right so perfect that's it i don't think we have to do anything here and then if you look at the image name the way it is going to create the image name is build repository name and then build id right so that would be nothing but so this is the repository name okay and then it is going to add the bill id as a tag right so that's what it is going to do so this is fine you can you can leave it like that that's fine okay and then click on push an image so again we have to do the same thing select the acr repo perfect okay and if you like to include the latest tag i mean you can you can do that if you if you want to tag it okay that's fine that's it right so so far so good and we also need to add a couple of more tasks because what we wanted to do is you know after you build the docker image we also need to go ahead and deploy the docker image into aks cluster right so for that we need to add a couple of more tasks so let me first add this task which is nothing but copy so i'm going to add this task okay so if you see here what i'm trying to do if you click on the dots so i want to you know add this kubernetes manifest file as part of the build itself right i want to you know add this file as part of the pipeline itself so that the aml file will be copied into a drop folder and your release pipeline can use that file for deployment okay so as part of the contents what i'm going to do i'm going to just mention the file name so go ahead and then mention the file name perfect and then where it is going to copy so you can click on this i and then mention that so it needs to go to the artifact staging directory so you can just mention like that perfect okay all right and then let me also add one more task because you need to publish it right you need to publish it so let's add that and then we're going to say publish build artifacts add okay so this one i think everything looks good you don't have to modify anything and this is going to copy the file from or whatever is available in the artifact staging directory into a drop location perfect i think i think we are good here okay all right so let's go ahead and then save and queue and let's see what is happening i'm gonna say save and run so right now it is in the process of uh getting an agent from the cloud and it's going to go ahead and then start the build process let's see as you can see here docker image has been built and it also tagged perfectly fine the repo name right and then this is the build id perfect oh we have some issue with pushing the docker image oh okay i think let's uh go back to the pipeline i think we missed one step oh yeah um okay i thought we already selected this push an image let me see i think let me go back to the pipeline one more time oh tag does not exist oh okay yeah yeah if you see here i have selected uh the latest tag so that is not that okay i think i know what is happening yeah if you see here i have included latest tag but when building i did not build with the latest so if you want you can just include this one okay so this is fine all right so that's fine let's go ahead and then say save and queue so we are going to build the darker image one more time there you go so now we are also able to see the latest image as well perfect so we are able to push that that's a good good one okay awesome so now the image has been successfully built and then we also able to upload into acr as well so if i go to azure portal if i click on the repo if i click on the repositories there you go so we should be able to see the docker image tags right there you go you see that so we also build with the latest tag and then we also build with the build id the reason why we see two entries here because our first bill got failed and then it created another bill right and this is what that one okay so perfect so so far so good and then of course you can click on any one of the image and then you can see and if you want to pull the docker image so this is how we are going to pull this is the latest docker image latest tag and if you want to pull a specific tag one this is how we are going to pull okay perfect awesome so let's go back to our instruction here so if you see here we successfully built the docker image by building azure build pipeline now what we have to do we have to create the release pipeline for deploying docker image into aks cluster but before we do ah so remember we talked about the kubernetes manifest file so we have to make sure that we do have proper entry right so if you go back to our our acr so the way we are doing it is so look at here right so we are tagging the docker image with the build id right and if you look at the kubernetes manifest file look at that so we are also doing that as well right so whatever the build id it has been tagging from the azure bill pipeline and during the release pipeline it is going to pick up this and then it is going to replace the build id dynamically right from the fro from from the variable right so this is like a what do you call predefined azure devops variable right which are nothing but see this is your build ids right so we will see that during the deployment okay i think we do have everything set up perfect and then this is for the services right so this is for deployment and then this is for exposing the spring boot application as a load balancer right so perfect all right so why don't we go ahead and then create the release pipeline so let me go to pipelines and then here i'm going to go to releases so let me create a new release pipeline okay so let's see click on new and then say new release pipeline okay so i'm going to choose the template here so let's see here okay so this is what we wanted to do right look at that deploy to kubernetes cluster this is exactly what we want to achieve okay so let me select this one there you go so the tasks have been added here perfect and then let's rename our release pipeline i'm going to say my awesome sorry springboard not ci this is cd or release pipeline whatever you want to do that i'm going to say my awesome springboard cd pipeline perfect save okay perfect so now let's click on the artifact so we have to link we have to link our a drop location right so if you remember we have created a docker image and then we also published our kubernetes manifest file during the build itself right so we need to link that so click on add okay and then we need to select our pipeline name i believe this one right my awesome springboard ci pipeline so just select that one perfect okay i think that's it okay perfect so it got added here so let me click on the stage name here i want to say deploy to aks okay perfect and then click on the task so these are the tasks so if you see right uh we want to deploy into kubernetes cluster and then we want to you know leverage the build id right so what we are going to do we are going to add a task here i'm going to say token so i'm going to add this task called replace tokens i'm going to move this to the top that's very important it should come before cuba city will apply okay and then here uh click on the three dots we have to choose wow that's interesting i don't see the drop location that's very interesting let me see wow wow do you all see the mistake what i have done i did not put i did not close the bracket so that's the reason why the drop folder was not there wow very interesting sorry about that guys we have to build this one more time so while this is building we can also see the previous build right so this is the previous build uh click on releases artifactory yeah see there's nothing got published okay yeah there you go see here so nothing because i made a mistake okay that's fine so that's good to know so here we go finally we see something okay i think we should be able to see that over here artifactory if not there published there you go yeah so there we go so this is what we need okay very good so let me go back to the release pipeline so my awesome springboard cd pipeline edit there we go over here yep click on the root directory fantastic there you go guys okay so this is what we need but you need to just choose the directory name don't select the file just the directory name perfect and then the file you are going to mention the file name right so that is nothing but this one so perfect and rest everything you can leave it as it is if you look at the token pattern and this is the pattern we follow right so so we are good with that perfect okay i think so far so good and then let's go to the cube ctl uh task so this is where we are going to connect with aks cluster right so we need to create a service connection so let's click on new okay we need to provide microsoft credentials let me approve in my phone through authenticator app perfect okay so now it should be able to show the cluster so this was the cluster what we created perfect and then you can select the namespace we did not create any namespace i'm going to go ahead with the default namespace and i'm going to say some name here i'm going to say my aks cluster since it's june i'm going to say june 2022 and then you might want to you know grant access to all pipeline so you need to select this one you don't have to use this one you don't have to so i'm going to leave that unchecked so that's it right so basically we choose the azure subscription selected the cluster name selected the namespace name and then we are entering the name for our service connection and then click on save perfect okay and then here we can go ahead and then mention the names space name which is default and then in the drop down what command we want to perform so obviously we want to say apply because it this will be like a cube ctl apply and then whatever the file name right and then this will go ahead and then deploy into aks cluster so click on use configuration file and then we have to provide our file name right so which is actually nothing but this one okay so let me just make sure the syntax is correct let me go back to my instruction here so apply yeah configuration file yeah that's it perfect okay all right very good i think that's pretty much over there i think that's pretty much over there okay all right so let's save this i'm gonna say created cd pipeline for aks deployment okay perfect um i think that's pretty much over there let's go ahead and then save this okay so saved and then let's go ahead and then create a release so click on create release click on create there you go so release got created so now let's see so click on the logs this will take couple of seconds it is waiting for the agent okay there you go so this is very important right so it replaced the build id right okay and then if you look at the next task cubesat will apply there you go so it says that deployment got created and then service also got created as well this is great perfect so let's go back to our item okay so now i should be able to use the cube ctrl command right so obviously we have two worker node and then if i say cube city will get parts or get deployments first there you go see here so we are able to see the deployment the reason why you see three because i do have three replicas there you go easier and then if i say get parts we should be able to see those three parts as well perfect okay and you can see here right like 49 seconds ago and then if you like to see the service okay so that's the service perfect so before that let's actually go ahead and then check the log so keep ctl logs and then provide the pod name there you go so let me expand this so as you can see here so this is the log for one of the part so as you can see here it started the springboard application right it initialized and then as you can see here it is actually up and running right started perfect okay and then of course uh we were looking at service here so if you see here we are exposing our service as a through load balancer and we are going to hit that using this external ip and i'm going to say call and then enter that ip so this should give me some output right and of course i can also go to browser and then check the output let me go ahead and then enter that oops sorry that's wrong let mean so we are going to use this ip wow look at that of course i do have some browser restriction here perfect you see here so this is our springboot application uh deployed in aks cluster and then if you want you can enter some name okay and then there you go and then if you want you can interview the name you know there you go all right so yeah so that's it guys you know that's how you would set up your aks cluster and then deploy your spring boot application which is your micro service into aks cluster using azure pipeline thank you for so before we close make sure you know you are deleting your cluster if you keep your cluster up and running obviously you will be charged a lot of money right so the way to fix that is you can go ahead and delete your resources right so you can execute this command this will clean up everything what you have done okay so i'm going to go ahead and then execute that so when you do that so everything will be cleaned up okay so so don't forget that so this this will take care of you know cleaning up your cluster awesome guys i hope this was really useful to you all thank you for watching this video once again appreciate that
Info
Channel: DevOps Coach
Views: 13,013
Rating: undefined out of 5
Keywords: AKS Tutorials Kubernetes Tutorials
Id: frII9e1XrzE
Channel Id: undefined
Length: 38min 31sec (2311 seconds)
Published: Fri Jul 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.