How to setup AKS Cluster & Deploy Springboot Microservices into AKS using Helm and Jenkins 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 deploy a springboot micro Services application into AKs cluster using Jenkins and helm so if you look at this diagram so let's take a use case let's say you are a devops engineer you are working with a team they are completely building micro services and they are deploying their micro Services into AKs cluster and you are asked to create a cacd pipeline uh you know in order to automate the end to end so how do you actually do that that's exactly what we are going to cover as part of this video so if you look at this diagram this is a spring boot application configured in GitHub and we need to create a Jenkins pipeline that is going to check out code from GitHub and the python is going to build the jar file build the docker image and then tag the docker image and then push the docker image into ACR and then finally pipeline will deploy the micro Services into AKs cluster using help okay so this is the process flow diagram which we are trying to achieve here all right so let's get started so if you look at the prerequisite yes we need to have Jenkins running Jenkins needs to have Docker installed okay so this is my Jenkins upon running this Jenkins is hosted on Azure cloud okay and I have already installed Docker on this Jenkins virtual machine so if you see here this is my Jenkins running on so this already has Docker installed okay and then if you if you also see here we also need to have Azure sale install Helm install and then Cube CTL install so I have already installed all of them over here okay if you also see Cube CTL that is also installed and then of course I also install Helm as well perfect so my Jenkins is hosted in Azure cloud I was able to install all the necessary CLI tools perfect and then this is my springboard application configured in GitHub so this is my springboot application configured in GitHub and then this is my Docker file so all we are doing is build the jar file okay and then I'm running you know these commands Okay in order to start my springboot application running in a Docker container all right awesome so how are we going to achieve this so yes we need to create AKs cluster okay because that is where we are going to deploy our springboot application and we need to create ACR as well so if you look at this diagram so this is our AKs cluster and then this is our Azure container registry so this is where we are going to store our Docker image and then this is where we are going to deploy okay and then we are going to create a namespace uh in the AKs cluster this is where we are going to deploy ah in this namespace only we are going to deploy our springboard application and then the way we are going to deploy is using help so help is the package manager for kubernetes applications um I have several videos on Helm so feel free to go through them okay but using Helm we are going to simplify our micro Services deployment so we are going to create a Helm chart I will quickly show you how to create a home chart locally and then how to commit the helm shot into GitHub and then once we create a Helm chart we need to modify the values so that you can mention the docker image name and everything right so so that Helm can use those files during deployment and then finally we are going to create a Jenkins Pipeline and that is going to have all the stages right we need to build a jar file build the docker image and then tag the image and then push the image in dacr and then finally we need to deploy and then finally we will verify the deployment the namespace and then finally we'll access the application in the browser yeah so these are the implementation steps so let's try to achieve one by one all right so let me take you guys to my website so this is my website folks coach devops.com I will be posting the link right below the video as well so I have all the steps documented very clearly over here okay so everything is documented so feel free to go through it and then if you actually see here the way we are going to create AKs cluster of course you can create a case cluster in so many different ways in fact if you go to my website if you just type AKs cluster creation here if we type AKs cluster you're gonna see there you go you see here right there are so many ways you can create a case cluster okay but I am going to simplify the AKs cluster creation I'm going to use a shell script because I have already created a shell script so click on this particular link so if you see here this is a script which is going to create AKs cluster as well as ACR repo and then the namespace as well okay so this is the name of the cluster and then this is the region where I'm going to create and then this is the cluster name sorry this is the group name sorry this is AKs the resource Group name because um so this is so so if you look at the shell script this is a resource Group that needs to be created because all the resources would be created under the resource Group and then this is the region and then this is the name of the AKs cluster and then this is a scr name okay so make sure you give unique ACR name and then if you see here first we are creating uh the resource Group and then we are creating AKs cluster with two worker nodes and then we are creating Azure container registry and then most importantly we need to give a pull access for AKs in order to download the image from ACR okay and then we need to configure our Cube credentials right so this is using this you will be able to access uh through Cube CDL command and then finally we need to create a namespace in the a case cluster using uh you know this particular command okay so this is where we are going to deploy our micro service inside a case cluster all right okay so let's go back here so why don't we start off with that okay and then of course I also have my source code in in GitHub so we will talk about that right so we will cover one by one okay so let me start my cluster creation so I'm going to go to my Jenkins so let me go to my Jenkins so if you see here uh the way we are going to create cluster is we need to switch into a Jenkins user first so I'm going to switch into Jenkins user okay very good and then I'm going to um I need to log into a case first okay because I need to authenticate with my Azure Cloud so of course there are so many ways you can authenticate you know with Azure Cloud you can use service principle and whatnot right but I'm going to simplify I'm going to log it into AKs cluster using Azure I'm going to log into AKs cluster using Azure CLI so let's type this command easy login so when you do that if you see here the best way to authenticate is yes you can copy this URL foreign and then go to browser all we have to do is enter this code so this is the code you just have to select your Microsoft credentials so click on this one and then you just have to say continue so you're giving permission uh in order to access Azure Cloud using Azure CLI click on continue that's it right that's it and then if you also go back so this also confirms that we are able to login into Azure Cloud successfully using Azure CLA command perfect so let me close this window I don't have to keep that open so let me go back to the instructions so let's continue so what we did we switched to a gen kids user and then I was able to login into Azure Cloud perfectly fine so now all we have to do is go ahead and then create AKs cluster using that shell script okay so I'm going to create a simple shell script file okay and then I'm going to go ahead and then copy the entire cell script like I said click on this link and then we are going to copy the entire shell script so this is just to simplify it is up to you if you want to create your AKs cluster there are so many ways like I mentioned but I just want to simplify our cluster creation so I would like to choose this option so make sure you don't have too many spaces here so what would happen is when you copy and paste sometime you know it may mess up you know with a lot of space so make sure you take care of it I know it's kind of annoying but uh that is what it is so don't give space especially in between that command so I think that should be it right so like I discussed like we discussed we are going to create cluster create ACR and then give pool access and then finally create a namespace as well all right great so why don't I save this all I have to do is execute this command execute the cell script there you go so as you can see here it is in the process of creating uh Resource Group and then creating a case cluster and then creating ACR repo okay so everything is going to happen so this might take maybe three to five minutes so while the cluster creation is happening why don't we move forward with the next step all we have to do is now create a Helm chart so we can you know keep everything ready all our configuration file everything you know we can keep it ready all right so what I'm going to do now since I have configured my GitHub here I also created so this is my visual studio code so I have already downloaded my source code over here okay so my source code is already configured in my local machine so if you see here they say git pull so you see here right so I have the entire source code here okay perfect so what we are going to do is we need to create a Helm chart okay so how do you create a Helm chart it's very simple all you have to do is you know use help create command so let me create a Helm chart so let's say Helm create and then I'm going to say um my AKs chart okay so again you can give any name make sure that this is in Thai with uh you know make sure that you give a name that is reference to your micro services or application or project name okay but for just for this demo purpose I'm kind of giving this a short name okay so now chart directory has been created there you go you see here right the chart directory has been created so so if you see here this is the directory here okay so if you're wondering how many files are created under that directory let's do this right there you go so four directions got created right look at that so a lot of files okay so help me is the package manager for kubernetes uh it is going to create all the templates for you you just have to uh you know go and modify the reference files and then you should be able to deploy your micro services so we are interested in couple of files let's start with the value.aml file so this is the file which is actually going to have the docker image information right you see here so they have just provided Engineers as example so we just need to modify this because this is we are going to store our dock image in ACR okay so so the way we are going to build our Docker image using Jenkins pipeline so this is the model what we are going to follow okay so if you see here this is the ACR right ACR repo what we are going to create so this is how the URL is going to be so you can update that and then the tag image tag we are going to um you know pass on this dynamically from Jenkins pipeline so don't use latest that is not recommended so I'm going to leave that as it is okay and then let's see here and then we also need to make sure that we need to change the service type as a load balancer okay so let's do one thing let's scroll down so let's go and make the change there you go so we need to change this as a load balancer just for this demo purpose of course you can you know free feel free to use your Ingress and everything right so you can you can do that so let me save this so that is the first change and then let's go to the next file so we need to modify the deployment.ml file since our application is springboard we need to open up that Port so go to deployment.aml file so if you look for the container port number that's supposed to be 8080 let's change it that's it so that's it right so those two files have been done and then all we have to do is save the files and then commit and then push into Repository so if I just say git status it says that yeah this ended directory got created right so now all we have to do is git add okay and then git commit minus M let's say added Helm chart for my micro service and then git push there you go so if I go into my GitHub if I say refresh here there you go right you all see here so our Helm chart has been pushed and then you can definitely see the the values got changed okay perfect some of the values got changed very good so let me go back to the instructions so why don't we check if the cluster got created or not it is still creating so while the cluster is being created why don't we go to our Jenkins so so this is our Jenkins right let's make sure uh the plugin is installed because Jenkins is going to use a docker the docker pipeline plugin so I have already installed I think if we go to install plugin you want to see the docker pipeline plugin got install very good there you guys you see here right uh the cluster got created and then it also created the namespace as well so we can verify real quick let's actually go ahead and then say cubesatel get notes wow there you go you all see here so we have two worker nodes that is what we actually created as part of our shell script isn't it so if I take you back to my cell script look at here guys we are creating AKs cluster with the two worker node okay node count two okay very good and then let's also go ahead and then look at the namespaces as well there you go so this is the namespace what we created from our sales curve so that is actually over here that's the last command okay very good right so so far so good and then of course if you want to see the ACR information and all let's go to Azure Cloud okay let's click on the resource Group because this was the resource Group what we created so everything is under that Resource Group okay and this is our ACR repo what we just created and so this is where we are going to upload our Docker image okay so Jenkins needs to have permission to ACR repo so that it can authenticate with the ACR wrapper and then it can uh you know upload the docker image okay all right so what would be the next step is yes we need to create the admin user and then we need to give we need to kind of authenticate uh from Jenkins into scr so we will do that shortly okay so everything is good right and then of course that is our cluster so this is our AKs cluster okay so you can you can see here right so if you want to click on the namespace so these are the namespaces that's our you know namespace name okay so everything you can actually see here okay so these are the things you know what has been deployed these are all uh all the Deep you know default deployments all right and then you can see here we have our two worker nodes perfect okay everything is looking good so why don't we move forward to the next step okay so scroll down over here everything I have documented here so let's go into Jenkins and then create these uh you know values right so since we are going to use Jenkins since it is a spring boot application we need to configure our build tool so we are going to use mav1 as the build tool so why don't we configure Maven here so I'm going to use Maven 3 and then save perfect and then let's also go ahead and then create some credentials in order for Jenkins to talk to authenticate with uh ACR so let's click on ADD credentials and then username and password right so let me go back to uh ACR here and then click on access keys okay so just enable admin user for now and then let's copy the username this is the username and then you can use either of this password let me use this password so don't worry guys this password will be deleted right after the demo so no one can access my ACR okay perfect so click on create so there you go right so we have created credentials for authenticating with ACR perfect so let's go back to our Jenkins here so now what we can do we can start creating a pipeline that can do all the automation right so let's start with the pipeline here let me click on new item so I'm going to click on my um Helm help deploy job click on Pipeline say okay go to pipeline okay so let me create a basic pipeline now hello world okay so let's start customizing our pipeline so we need to check out code okay so from where I'm going to check out I'm going to check out from my GitHub repository okay so I have already made this as a public repo so uh you know anyone can Fork my repository and then make changes in the respective file if you like check out for Version Control repo URL and then since this is a public repository you don't have to provide any credentials and then what is the branch name the branch name is Master so I can leave that as it is Master is here and then generate pipeline script there you go so this is the code for checking out from my GitHub very good and then what is the next stage the next stage is you know we need to build the jar file isn't it so I'm going to say build jar and we are going to use May 1 for that okay so I'm going to say something like Maven clean install okay so that should take care of creating the jar file so apply save so before I go to four I just want to make sure that our pipeline code is working fine there you go there you go guys the image has been built the next step would be to build a Docker image okay so for that what we have to do we need to provide all this information right so I'm going to create a environment section here okay so I'm going to provide my registry information here right so let me create a variable called registry so you all know the registry URL right we we already got it from our uh you know ACR let's go back here and then provide the registry information over there okay and then let's also create a couple of variables as well so if you remember we also uh created a credentials right in Jenkins let me use that as a registry credential that name is ACR okay and then um let's create another variable called registry name the registry name is nothing but this one right we already have that that registered name is nothing but this one okay all right and then I'm going to create a variable called Docker image perfect okay all right so let's go ahead and then build the docker image so I'm going to go here stage I'm going to say build image steps I'm going to save we are going to use script block then Docker dot bill registry okay and then you can store this in a Docker image okay and then you can tag a Docker image so tagging the docker image is really recommended okay so the way we are going to tag is we are going to pass on foreign yeah we will okay while pushing the docker image we will tag it okay so we can leave it like that for now so this is fine for now let's build it build the docker image okay and you can also see that this also this is being tagged with the latest image that's fine we will fix it when we upload our Docker image very good so the docker image has been built so the next step would be to upload the docker image into ACR I'm going to say upload to ACR steps block okay and then we just have to use this command so let me copy and paste there's nothing wrong okay so this is the registry URL we have already provided over here okay and then we want to push the image like that okay so apply and Save oh I want too many there you go okay apply save till now okay so the image is oh okay so because I'm using wrong credentials the registry credential let me show this one it's okay so let's check the console output so it is failing for some reason it says that no such property registry URL okay so let me see if I made a typo let's go to configure go to pipeline uh let's see here okay so this is the variable name I'm actually using oh I don't have declared that I made a typo here okay let me fix that there we go so that's the registry URL so if you look at the pipeline stage this is going to authenticate right with this ACR repo with this credential and then it's going to tag the docker image based on the bill number so this is the default variable from Jenkins so save it click on build now awesome there you go guys as you can see here perfect see here so it was able to authenticate with the it was able to authenticate with the ACR and then you know finally able to tag the docker image and then push the docker image perfect so if I go into ACR so go to Resource Group here click on container registry and then click on repositories there you go this is our repository so click on it there you go guys do you all see that so the image has been tagged dynamically and then you can also see the timing here as well perfect awesome right so we are able to build the docker image successfully and then push the docker image into ACR so all we have to do is move on to the next stage which is nothing but Helm deployment okay so let me go back to the pipeline configure pipeline all we have to do is go ahead and then write the next stage I'm going to go back here stage this is nothing but Helm deploy steps block script block okay so how are you going to write the code here so we are going to use helm okay Helm upgrade okay and let's get the code from here so I will explain you everything so if you see here I want to have a dynamic bill number that's what I have here okay so that's the version okay and then install we need to provide the chart name so if you see here if you see here this is the chart name let me fix that okay and then the namespace so the namespace is this one will be just created a few moments ago Helm deployment is the namespace isn't it foreign space perfect and then the image tag so what we are going to do we want to pass the image tag dynamically so that is what it is right if you see here this is the bill number right that's a Jenkins bill number so that's what we want to use okay so the image tag will be passed dynamically okay so this is what we are trying to help upgrade version this and then install okay and then our chart name our namespace name and then the image tag that's it okay so apply save click on Bill now wow see here guys so it was trying to see that whether the version exists it say the version does not exist so it is trying to install so it was able to install so now we should be able to access our application so all we have to do is go back to our Jenkins ec2 instance sorry Jenkins virtual machine and then say Cube CTL get uh parts obviously you don't see anything because you need to pass on the the namespace name perfect there you go see here guys so that is our deployment of course you can also use Helm command as well you can say Helm list if you say that you don't see anything because you need to pass the namespace so let me use Helm LS and then provide a namespace there you go so that is our release detail right okay so how do you access the application now so let's try to use Cube CTL get service because we are exposing our service through a load balancer there you go so this is the uh still taking some time to create that I think it will take some time let's let's give some time so why don't I check the portal locks while it is coming up I'm going to say Cube Ctrl describe pod and then the part name and then the name space let me see what it says wow say it is successfully assigned so obviously right so let me check the services now now it should be up and running there you go you all see that so copy that IP go to the browser there you go guys you all see that so now we are able to access the spring boot application which is deployed inside a case cluster so why don't we do one thing why don't we make a quick code change and then see if you are able to see uh you know the changes are reflected ah in in the application right so let me go into my repo so this is my repo let me make some code changes here go to SRC Main let me go here let me edit this file so basically all the values are coming from here okay so let me do one thing let me make some changes here I'm gonna say we are deploying springboard application inside a case cluster using Helm shot and Jenkins pipeline uh let me know one thing I'm gonna say hello all are testing springboard deployment with help Jenkins pipeline okay so let me save this comment changes click on Commit all right so I committed the code and of course the way you have configured Jenkins you can also configure through webbooks and whatnot isn't it depending on how you want to con run your pipeline but I'm going to run manually for now so let's see what it does so it was able to pick up my code changes remember we updated that file let's see okay so building the image it is trying to upload the image so we can also go into ACR click on the repositories so time is 10 40 so there you go the image has been uploaded here perfect there you go the changes also has been pushed here so how do you see that let's go here and then let's say helmless there you go guys as you can see here it was able to deploy the newer version of the changes here okay let's try to see the pod there you go the new part also has been deployed okay it should actually delete the world pod okay I need to check my code why it is not deleting because we don't want to keep our old code running isn't it okay so I will take a look at it why it is happening like that but let me go into my let's try to view the service as well there you go so this is the service external IP let me go and try to access that there you go guys you all see that we are able to see the code changes all right so everything is looking good last but not the least we also need to clean up our cluster as well don't ever forget that otherwise you know you would be charged from Azure so let's go ahead and then delete whatever we have created so how do you do that you can use again right you can use uh the Azure CLI command all you have to do is just delete the resource Group whatever we have created so if you remember the resource Group name you can go here and then you can pick up the resource Group what we just created this was the resource Group name let's pass on that one and then of course you're going to pass on the you just have to say yes no wait right so it doesn't have to you don't have to wait for that okay that's it so this will take some time okay it may take two to three minutes in order to clean up everything what we have done all right so that's it guys you know that's how you would deploy your spring boot micro Services into AKs cluster using Jenkins and l thank you for watching this video
Info
Channel: DevOps Coach
Views: 2,358
Rating: undefined out of 5
Keywords: How to Automate springboot Microservices Deployment to AKS Cluster using Jenkins pipeline and Helm, Deployment of Springboot app into AKS cluster using Jenkins pipeline and Helm, Helm Deployment to AKS Cluster using Jenkins Pipeline, How to Deploy Microservices to AKS Cluster using Jenkins Pipeline and Helm, Create CICD pipeline for Microservices Deployment to AKS cluster
Id: fdzuMGSIz8A
Channel Id: undefined
Length: 38min 3sec (2283 seconds)
Published: Tue Jun 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.