Setup AKS Cluster & Deploy Springboot Docker Container to AKS Cluster using Helm and Azure Pipeline

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back in this video we are going to learn how to deploy a springboot micro Services into AKs cluster using Helm and Azure pipeline so what is Helm Helm is the package manager for kubernetes whenever you are trying to deploy uh your micro Services into kubernetes cluster it is recommended to use help why because help me is going to allow you to package all your kubernetes uh you know manifest into something called Helm chart and then using help chart you will be able to deploy your micro Services into kubernetes cluster so that's exactly what we are trying to achieve in this demo okay so if you look at this diagram we are going to create two different type of pipelines in Azure Azure devops we are going to create a build pipeline okay and then we will also create a release pipeline so let's try to understand how we are going to do this so the Azure build pipeline will check out the code from GitHub it will automate the the jar file creation it will automate the docker image creation and then it will also tag the docker image and then push the docker image into Azure container registry okay and then it will also package the helm chart file as well okay so that is what Azure build pipeline will do and then the release pipeline is going to pick up the package chart file from the build Pipeline and then it will go ahead and then deploy micro Services into AKs cluster right so two different type of pipeline we are going to create so using these two pipelines we should be able to achieve this so let's look at the implementation steps okay so if you look at the prerequisite we need to have Azure subscription created okay everything what we are going to do like creating the AKs cluster creating Azure container registry everything would be part of that Azure subscription and then we will be creating AKs cluster okay and then in order to do that we need to have Azure CLI installed okay and yes we also need to have Helm install as well and then we need to have Cube CTL install as well and then finally we need to have our springboot app configure okay that I have already configured in GitHub okay and then how are we going to achieve it so what are the implementation steps you see here okay we need to create a resource Group in Azure cloud and then we'll be creating AKs cluster and Azure container registry under the resource Group and then once the cluster is created we would be providing full access for AKs cluster in order to download the image from ACR okay and then we will create a namespace in the AKs cluster because this is where we are going to deploy our springboot micro services in this particular namespace inside the AKs cluster and then we will create a Helm chart for our springboot application and then we will create a build Pipeline and then customize our Pipeline with the help task and then we will also create a release Pipeline and we will customize Pipeline with the help task for deploying application into AKs cluster and then finally we will verify the deployment inside the namespace in the AKs cluster and then we will use Cube CTL port forward in order to access application locally and then finally we will try to access the spring boot application in the browser right so yes we are trying to you know do all of this thing right so let's try to achieve this one by one okay this will be a little bit long demo but I will try my level best to you know customize the best it can be very good so let me take you guys to my website here so this is my website folks coach devops.com I will be posting the link right below the video as well so let's try to understand what is help so like I explained you earlier help me is the package manager for kubernetes okay it is something similar to um you know apt in Ubuntu or MN Red Hat operating system right so using this Mr apt we will be able to install any software on the respective operating system right so same thing with help so using this Helm you can easily manage your kubernetes uh you know deployment right so especially you know when you are dealing with the set of micro Services you may end up having lot of kubernetes resources right you may end up having lot of kubernetes manifest file so how are you going to you know structure all your kubernetes manifest files so this is where what you can do you can create something called Helm chart so when you create a Helm chart you're going to have this director structure right so it's going to have a chart chart name and then it's going to have a bunch of kubernetes manifest file all you have to do is just configure this file and then you know go ahead and then make changes and then you will be able to you know package it and then deploy inside AKs cluster so that's what we are trying to achieve in this demo all right fantastic so let's get started here so obviously um you know let me actually take you guys to my local Mission here yeah if you see here I have already installed Helm I also installed Azure CLI as well I also install cubectl as well as you can see here okay so these are all CLI utilities so I will install all of them okay so now what we are going to do is we need to First go ahead and then create AKs cluster so I also simplified that as well so if you look at my link here so when you click on this particular link this will take you to a shell script so if you see here I have created a shell script which is going to create AKs cluster it will also create Azure container registry and then it will also uh you know create a namespace as well and then as part of the script it will also provide the required permission for AKs cluster in order to download the docker image from ACR as well right so everything is taken care I mean most of the task has been taken care here of course if you want you can also you know like execute all this step one by one but I just want to simplify the whole setup okay so let's go ahead and then create a cell script so I have already created a cell script here and if you see here this is the script name create aksar so let me just do cat command on that there you go you see here right so that is my shell script okay so I have already mentioned everything and the Y creating make sure you have unique ACR name okay make sure you have a unique ACR name if you don't have this name unique uh your Michelle script execution will fail okay so this has to be unique okay perfect so why don't we go ahead and then execute that shell script so I'm going to go ahead and then execute it but before that uh we must login into Azure uh portal so you're going to execute this particular command so this will take you to here and then click on you know click on your Microsoft account and that's it right so now we are logged in into Azure Cloud perfect as you can see here so now we can go ahead and then execute the script so this might take easily uh three to five minutes so while the cluster creation is happening why don't we go ahead and then review our remaining steps okay so yes this is going to be created and then this also will be taken care I think the first three tasks will be taken care as part of uh the script okay and then if you look at the next set of tasks we need to create a Helm chart for our spring boot application so if you see here this is my spring boot application okay I have checked in in GitHub this is also publicly available as well I will make it make it I'll make sure this repo is available publicly for for everyone okay I also have a you know Helm chart created here but I can actually show you how to create a Helm chart okay real quick so let me take you to my visual studio code lady created a Helm chart that's fine I will quickly show you how to create a help chart this is very very easy okay all you have to do is just say help create and then you're just going to mention uh the name of the chart okay so you can say maybe my charts okay okay so so when you do that this will go ahead and then create a Helm shot for you but let me look at the naming convention here let me see what is the existing chart I have oh I already have my chart so let me do one thing let me go ahead and then create my AKs charts okay I may have this one I already have one let me do one thing let me just go ahead and delete that folder uh okay so let me go ahead and then create this uh chart okay now we are going to create a chart directly with this name enter there you go as you can see here it is creating uh it is actually already created you see here guys so this has created this directory so if you like to uh the see the content of this directory I have already installed a utility called tree so let's try to execute that let's try to view the whole directory there you go can you all see that so this is the directory name and then it has created bunch of kubernetes manifest okay and chart.aml file and then you have a bunch of bunch of files okay so depending on the type of resources kubernetes resources you will be using you will be making and changes in the respective files okay so in our case since we are going to if you look at this diagram if you look at this diagram we are going to create a Docker image and then upload the docker image into ACR and then we are going to deploy uh that Docker image into AKs cluster right so all we have to do is we just need to go to our Valley start AML file and then make changes in that valleys.xml ml file to you know we just need to update our Docker image path because this is where we are going to upload the docker image and then this is the format we are going to uh you know use in order to you know upload the docker image and tag the docker image okay so okay so we need to open up this value.aml file so if you see here so this is our chart directory when you go inside sorry not that one this one okay so I can show you here there you go you see here so currently they have mentioned in nginx so you just need to modify that okay so I kind of know how the build pipeline is going to create the image so it is going to have this naming convention I kind of know so I'm going to go ahead and then make the change okay so this is the docker image we are going to build using that Azure build pipeline okay and then tagging I want to override the tagging uh you know from my pipeline so I'm going to leave it like that don't use default that is not recommended but we are going to I know like build a Docker image dynamically and we are also going to tag the docker image dynamically and then we will also you know deploy dynamically as well okay so I'm going to leave the tag as it is and then if you look at the deployment ml file uh so which is actually nothing but inside the templates folder let me go to diploma.aml file so this is where we are going to mention our container Port there you go so currently it says 80 but we are we are going to say 8080 so let me just mention that as well so that's it right these two changes what we will be doing as part of our our code so let me save this also so again right I know it's a very simple use case we are just picking up a spring boot application then deploying into AKs cluster I'm not using all the you know kubernetes resources I'm not using service account or anything like that but but feel free to modify whatever you know based on your requirement okay very good so I made changes in a two different file so why don't we quickly go ahead and then and then you know uh check in these files right so let me do one thing let me clear the screen I'm going to say git status here it's going to show me these two files got modified uh hang on let me see here did I save okay there you go so we are able to see the whole folder got created right very good so what I'm going to do I'm going to go ahead and then add that right I'm going to say git add I'm going to add this folder perfect so if I say git status there you go so all the files will be checked in okay very good uh let me go ahead and then commit so I mean what I'm trying to do is I'm I'm you know I'm creating this Helm chart and I'm also storing that Helm chart as part of my code base but it is up to you your company may follow a separate Helm repo so in that case you will be committing all the help files for that respective application inside that Helm repo right but again you know you can follow whatever the best practice you know your company is following but in my case it's a very simple deployment I'm actually storing all the helm related files as part of the source code itself okay perfect so let me go ahead and then say created film chart for a springboard for springboard app okay and then I'm going to go ahead and then perform git push okay so I do see it's rejecting okay I think I may not have latest code so I'm performing git full I'm going to go ahead and then merge the phylia motors again push perfect okay so if I go back into my repo we should be able to see there you go guys there you see here so this is the helm chart what we just created and then we also made few changes so as you can see here I updated the image image name here and then I leave this open and then I also updated in the valleys.aml file I also update sorry uh in templates deployment file deployment manifest file I also made sure that you know this is this is updated right and then as you can see here obviously right it's gonna pull wherever it is right everything is kind of connected that's the great thing about Helm chart you don't have to do anything you make changes one file and then it has it has a way of you know referring them from respective file perfect so our Helm chart is been created and then we were able to update the helm chart as well perfect that's awesome actually so let me go back to the implementation steps so we are pretty much done here so now why don't we go ahead and then check on our our all our resource creation wow see here guys let me expand this wow see here so I'm able to see your namespace got created I think pretty much all the resources got created this is amazing so like I said this actually took less than like what you know five minutes for sure no doubt about that all right so why don't we go ahead and then check all our resources are created or not so let me perform few Cube CTL command let me go ahead and say cubesatel get nodes there you go so as you can see here we are creating two worker node and of course you can see in my shell script that we are creating two worker node perfect okay very good and then let me also see here of course if you say part there's nothing is there right we never executed anything we never deployed anything and then let me try to get the namespace name there you go so of course these are all system uh default name spacer but we have created this one help deployment perfect so so far so good uh very good and then let me see here right and then of course if you want to check on the ACR you can go into Azure portal Okay click on the resource groups so if you remember this is the resource Group name what we had created correct so if you look at the shell script so this is the resource Group name so all the resources would be created under that resource there you go so this is our repo name and this is our AKs cluster perfect so so far so good all we have to do is you know log it into our Azure devops dashboard and then start creating the build Pipeline and then start creating the release pipeline so so far so good right okay so let me log it into my Azure devops dashboard so this is my Azure devops dashboard I have already created a you know organization whatever you call analytic not organization already created a project dashboard under that okay so I'm gonna go to pipeline so let's start creating a build pipeline right so I'm going to actually go ahead with the classic pipeline okay in this in this video uh maybe I can create a separate video where we can talk about you know how to automate this using amml pipeline okay but let's try to understand the process right by by using a classic pipeline so let me click on new pipeline okay so I'm going to go with the classic editor okay so where is our source code our source code is in GitHub so click on that one so I have already created a service connection for GitHub okay so all I have to do is just select on this click on this three Dot and then select my repository so this is my repository a Docker springboard so let me copy that repo name and then just type here it should be able to pull up there you go so this is my repo name click on that one click on select and what is the branch name I think the branch name is master perfect so we are good with that go ahead and then click on continue very good so now it is asking us to select a template so what I'm going to do uh since we are going to use Helm I'm going to go ahead and then type Helm here there you go right you see here so that's a great thing about Microsoft they have already created a template for us to use so you know this is a great way of you know creating your pipeline with the setup predefined task and then you can customize the way you want so let me go and then click on apply so if you see here as you can see it's going to say build a container image push into specified container registry after the push is complete uh package the helm chart and then publish this as an artifact right so that's exactly what we are trying to do so click on apply there you go so as I was saying it has created this Pipeline with all the tasks pre-populated all we have to do is you know just start customizing one by one okay all right so if you see here uh let's try to take care of all the red mark here so obviously we need to First select the agent do not select Windows agent okay it is recommended to use any Linux agent so I'm going to go with Ubuntu latest perfect okay and then click on get source so we we already took care of that and then and then let's try to review the task one by one right so it's going to build the image push the image into ACR and then install Helm this is not needed okay we don't need to initialize help this is actually part of Helm version two but we are going to use Helm version 3 so I'm going to remove this task okay we don't need this at all okay and then we will come back to this task we are going to customize this anyway so if you see here there is no jar file task right like you know there is no way of building uh the jar file right so it's very simple just just click on add task and then add okay so let's add this task okay and then I'm going to move this up okay there you go okay so let's customize this so click on the three dots okay so palm.xml file so that's our repo okay and then I'm going to say clean install okay perfect okay and then this particular task is going to build the docker image okay so let's select the Azure subscription okay so that is my Azure subscription okay so there you go it's already scoped and then what is my Azure container registry just select this drop down there you go so that is our Azure container registry name and then I'm going to leave everything as it is okay and then the way it is going to build the image it is going to have a repository name and then the build ID right so that's exactly what we have specified as part of our you know valleys.aml file right if you see here the ACR name right and then the repo name right okay so that's exactly what what we have right so so that's what it is okay it's up to you so if you are changing here then of course you also need to go back and then change you know in your value start ml file right so you also need to modify which is nothing but over here so depending on however you are you know building your Docker image so you have you'll have to modify here and then of course the tag as well okay perfect so let's go back so I'm going to leave everything default but if you like to build the latest uh tag also if you want you can also do that so then in that case it's going to create two tags one with the you know that the default I mean one with the build ID tag and then it will also create a latest tag as well but I don't want to use later Stacks I'm going to leave it like that okay and then this particular task is for pushing the docker image into ACR so very simple let's go ahead and then select our Azure subscription and then select our repo okay and then I'm going to leave it like that there you go same thing over here while pushing if you want to include the latest Arc you can do that but but I don't want I don't need that so I'm going to leave it like that okay and then finally this particular task is going to install Helm so make sure you check this because this is going to install the latest version of Helm which is like three point something so yeah so make sure you check that perfect and then look at this particular task so basically what we are going to do is after the image is created right after we push into ACR so what we need to do is we we need to package all our Helm files right so when I say package means whatever the Hem chart you know Helm chart we created we want to package it this as a as a zip file or tar file whatever it is right so that's what this is going to do and then in the release pipeline we are going to refer that packaged artifact and then we are going to go ahead and then deploy it okay so we just need to provide the path so if you see here if you click on the drop down you you're going to see all the helm commands correct but but we want to package as part of the build pipeline okay so click on the three dot so let's select our chart directory so this is a chart directory what we just created few minutes ago so I'm going to select that and then click on OK you just have to provide the root of the directory you don't have to select any files you know as as such so just leave it like that and then let's keep going uh version if you want you can provide the version and all I'm going to leave it as it is that's fine destination so it says that where it is going to uh you know uh like drop the file so as you can see here it is going to put it in the staging area right staging directory and then if you click on the artifact uh task publish artifact task and is going to pick up from there right okay and then it is going to make sure that it is available for for the Azure pipeline okay perfect so that's that's pretty much over there uh but before I save on Q let me go and review my instructions so I have provided pretty much all the steps documented here so you can always verify right you if you're missing anything there you go so we provided that we already removed this one uh we provided the you know the chart directory here perfect okay so this is also good perfect I think I think so far so good all we have to do is just go ahead and then click on Save and queue all right so let me do that 7q okay and click on save and run so it might take maybe you know 45 to 60 seconds let's see so we have selected Ubuntu as the build agent so that's a good thing wow see here guys it took about 56 seconds to complete the entire activity very good so there you go so if you see here this is the chart package name right so this is how we have packaged it okay very good and then of course you can also see the docker image as well there you go do you see here and of course we can verify whether the docker image has been pushed into ACR right so why don't we do that let's click on the repo name okay ACR report name and then go to repositories under services and then you see it so this has created this entry and then click on it bill as you can see here wonderful okay awesome so let's go back let's go back to our pipeline so our build pipeline has been created and it has been uh you know it has executed what it's supposed to do okay very good so now we are going to move on to the next tab where we are going to go ahead and then create a release pipeline okay fantastic let's go back to our pipeline okay so I'm going to click on uh releases here let's click on a new pipeline so you can click on new release pipeline okay so here it is asking for that template again right so again choosing the template is recommended so let me go ahead and then type helm okay there you go so I'm going to go ahead and then use this particular Helm task okay let me just make sure there you go easy so you type Helm and then you are going to use that particular template okay so let's select this template and as you can see here this will take care of deploying um spring boot application inside uh inside cluster using help chart so click on apply okay and then if you want you can customize this task you can say AKs deploy okay uh just uh just a stage name okay perfect now the first step would be uh this is a release pipeline right so we need to add an artifact so the source for this pipeline would be our our you know CI pipeline right our build pipeline so if I remember correctly I think this is our pipeline name let me verify that I just want to make sure that it's right let me just add it and then and then we'll go ahead and verify so let me make sure I know I have a couple of pipelines over there so if you see here there you go so this is our pipeline right I know I would have done a good naming convention there but if you want if you want to change your pipeline name it's very simple you can go ahead and then change your pipeline name right here if you want actually why don't we do that I'm going to say my uh springboot okay and then I will say Helm as well okay let me save I just saved it okay and then if I go back to my foreign so let me refer again there you go you see here okay perfect add very good okay all right so now we have to go ahead and then customize our pipeline task so click on this one so there you go so it has created three different tasks as part of selecting the template and if you want you can rename the pipeline so let's rename the release pipeline I'm gonna say my pipeline okay so perfect okay so let's start customizing it so click on the uh the stage name and if you see here yes we have to select our Azure subscription perfect and then select the resource Group there you go and then select our kubernetes cluster name our a case cluster name perfect we are good with that okay wonderful foreign let me see here yeah let's go back here and then click on the agent so again right I would choose uh Ubuntu so click on Azure pipeline like host Azure pipeline right and then select Ubuntu okay very good uh and then yeah so this you can leave it as it is install we need to have help me install on the agent and then we don't need this task okay so you don't need this task at all so you can remove it help in it we don't need it that is part of help version two okay so this is where we are actually interested in right so what we have to do here uh we have to choose okay so we need to choose um our our you know the package short file right but before that let's let's try to make sure few other changes are taken care so you see here it is asking for the namespace name so if you remember we have created a namespace correct I think if you see here yeah there you go okay so this is our namespace so let's copy that Helm deployment and let's go to the release pipeline just mention that okay very good and then the command yeah you can leave it upgrade is fine and then it is asking for the file path right chart type file path so yeah so so you know yes we have already created uh you know you know we already packaged our chart file so you're gonna select file path and then click on this three dots and simply go to the drop location here and then you select our chart that's it package chart file that's it that's all we have to do and click on OK very good and then it is asking for the version so version remember we did not mention anything so I'm going to leave it like that and then it is asking for the release name so you can give any name again depending on your release you can say my release or whatever so that's fine and then yeah okay so this is where it gets interesting right set values so if you remember if you look kubernetes manifest file one of the Manifest file if you look at valleys.aml file if you remember you see here we are not using latest tag or anything like that right because we are going to override okay we are going to override the tag from the pipeline itself so the way we are going to override the uh you know the docker images if you see here the docker tag is uh if you look at the the build pipelines remember we have added some tag right so which is actually nothing but here I'll show you so remember so we are doing that right so remember we are just we are just tagging with the build ID you see here right so all we have to do is we just have to go here go to the release Pipeline and then just mention like that image tag equal to you know the build ID okay so which is actually nothing but again you go here so if you see here all these are Bill numbers right so we are tagging based on the build ID and then we are just picking up that we're doing a deployment right so that's all so this is very important if you don't do this then you know pipeline uh it will deploy but it will not be able to download the image from ACR properly okay so that's it right uh that's pretty much over there let me let me go back and then verify uh everything I think everything is good rest everything you can leave it as it is wonderful okay all right so let me save the release pipeline oh before that so if you see here you also have option to trigger this right if you want to trigger the release pipeline right after the build pipeline has been built so you can enable this if you like okay so whenever the the build pipeline you know completes it will automatically trigger the release pipeline so if you want to enable that you can you can you know very well do that okay all right so let me save it okay so now we have created a release pipeline so all we have to do is go ahead and then create the release so let me click on create release okay and then click on create there you go so click on the release one fantastic so right now it is in the process of uh you know picking up from the queue let's see perfect so you can see here it downloaded the artifact the helm chart files so you can see this one okay so something is wrong so list name is invalid yes okay let me see okay I think I might have a different okay I think it does not like that naming convention so let me go ahead and then say first okay let me give some name okay I think that should be fine okay let me go ahead and then click on create release again okay so currently it is in the process of deploying wow look at here guys so help upgrade task was able to deploy successfully into a case cluster okay look at that it says that the list does not exist trying to install now deployed okay it also created a revision as well perfect okay so how do you check this it's very simple let's go into our kubernetes cluster so I'm going to say Cube CTL gets part and then of course we need to pass on the namespace name don't forget there you go guys look at here you all see that so we are able to see the Pod name right so this is the part name okay so we just created one part so we're able to see the part and then it says that part is running and then you know like it's been like what you know almost like 50 seconds perfect so now how do you access how do you access the part so but before that let's check few things let me go to describe keeps it will describe part and then mention the part name okay and then mentioned the name space name so sometime if your pod is not coming up so what you can do you can go inside uh you know the part just check the Pod locks okay so this will tell you whether your part is running or not but we are good right so our part is running perfect okay uh so now we are going to perform Cube CTL port forward because we want to access uh you know the spring boot application locally uh in our machine so it's very simple so how do you do that so we are going to use Cube CTL port forward command okay put forward and then you just have to mention the part name okay so what is our part name so this is our part name okay foreign okay and then uh colon 80 sorry uh 8080 and then just mention the namespace name space okay there you go so it says that you know it's forwarding to localhost 8080 so I'm going to open up a browser wow wow see here guys so this is our spring boot application which has been deployed inside AKs cluster using help you see here so we are able to see this application you know which is deployed a case cluster but we are able to access locally because we did use the port forward so yeah so that's it guys you know that's how you would you know deploy your application into AKs cluster that's how you deploy your spring boot application inside a case cluster uh using help before I let you all go folks last but not the least it is also important that we need to clean up the resources as well right so I also have a command in order to achieve that so if you go to the bottom of my uh web page of that particular article you see here so we also need to clean up the resources so that's a great thing about Azure CLI all you have to do is just delete the resource Group when you delete the resource Group everything else as part of the resources will be deleted right so what I'm going to do I'm going to go ahead and then perform this particular command so this will take care of you know deleting all the resources under that Resource Group all right so yeah so that's all guys that's all we have for this particular demo thank you for watching this video
Info
Channel: DevOps Coach
Views: 4,369
Rating: undefined out of 5
Keywords: Springboot Deployment to AKS Cluster, Helm Deployment to AKS cluster, Microservices Deployment into AKS Cluster using Azure Devops pipelines
Id: TSufDgRBfdg
Channel Id: undefined
Length: 39min 56sec (2396 seconds)
Published: Thu May 04 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.