How to setup EKS Cluster & Deploy Springboot Microservices into EKS using Helm and Jenkins Pipeline

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right welcome back folks in this video we are going to learn how to deploy a spring boot micro Services into eks cluster using Helm and Jenkins pipeline so if you look at this diagram we need to have eks cluster configured okay so this is a eks cluster configured with two worker nodes and then we also have ECR repo configured here as well in AWS Cloud okay and then this is our GitHub okay so I have configured my springboot application inside GitHub and we are going to create a Jenkins pipeline so I have configured my Jenkins over here so we are going to create a Jenkins pipeline that is going to check out the code from GitHub it is going to build the jar file using Maven it is going to build the docker image and then tag the docker image and then push the docker image into ECR and then finally using help chart we are going to deploy the docker image from ECR into eks cluster this is very simple use case this use case is really based on real-time scenarios we also have a similar type of deployment cs80 pipeline in my current project as well where I am working so this will be extremely useful for people you know who's learning devops or or who is already you know into devops but you know if you wanted to deploy uh your springboat application inside kubernetes cluster using Helm chart and Jenkins pipeline so this is a great video for you awesome guys so let's get started so if you look at the prerequisite obviously we need to have eks cluster configured and we also need to have ECR repo as well we are going to set up eks cluster using eks CTL command so we're going to talk about that in a minute and then we need to have ECR repo for storing the docker image and then we need to have all these CLI commands or CLI tools installed we need to have AWS CLI we need to have help CLI we need to have Cube CTL and then we also need to have EK CTL as well and then of course we also have our spring boot application as well right so we have already configured that in Gita okay so how are you going to implement all of this thing right so we need to First create the eks cluster using EK CTL command so I also have a separate video on how to set up eks cluster using EK CTL command as well if you are interested you can definitely watch that video I will also post the link in my in the description as well okay and then we also need to have ECR repo okay for storing the docker image and then we are going to create a namespace inside eks cluster this is where we are going to deploy our springboot application inside the eks cluster okay so namespace is nothing but it's kind of a logical uh you know a grouping if you have several micro Services you can group them right under a namespace inside of your kubernetes cluster and then we are going to create a Helm chart for our springboot application and then we are going to modify values right we are going to modify the helm chart based on our Docker image values and whatnot right so that's what we are going to do inside the helm chart and then we are going to create a Jenkins Pipeline with all the all the stages here right so that's going to build the jar file build the docker image tag the docker image and then push the docker image into ECR and then finally we are going to use a Helm command in order to deploy that spring boot application or Docker container from ECR into e-case cluster okay and then most importantly we are going to uh you know use Dynamic Docker image stack okay so we are also going to build the docker image dynamically and then we will also you know download the docker image from ECR in a dynamic Manner and then we will we will pass that uh Docker image right during the deployment as well okay so we are not going to use the latest tag we are going to use uh the dynamic Docker image tag okay once a spring boot application is deployed and then we are going to verify the deployments in the namespace inside eks cluster and then finally we are going to access the application okay so yeah so these are the Implement implementation steps yes set up the cluster create a namespace and then create a help chart make changes inside the helm chart and then you know create a config entry inside Jenkins and then create a pipeline and then and then verify the deployment okay awesome so let's get started so I'm going to take you guys to my website coachdevops.com I will be posting the link right below the video as well so if you see here uh yes we need to have eks cluster configured we also need to have Jenkins up and running so I already have my Jenkins instance up and running so this is my Jenkins instance okay I have configured inside AWS cloud perfect so this is my Jenkins so if you see here right we also need to have AWS CLI install Helm install and all so I don't have anything okay so we are going to go ahead and then start installing one by one okay so let's start with setting up AWS CLI so click on that link so this is going to give you all the steps for you in order to configure AWS CLI AWS CLA now perfect so let's go ahead and install help okay so we need to install Helm so yes there are several ways you can install help but I'm going to use the scripting approach so I'm going to download the scripts okay I'm going to change mod and then let's install helm okay and then you can verify real quick whether Helm is installed or not so we are going to use Helm 3 we are not using Helm version 2 we are using version three so just remember that and then let's also go ahead and install Cube CDL as well so Cube city is being installed and you can also check the version right perfect so we took care of AWS CLI we took care of Helm we took care of installing Cube CDL and then we also need to go ahead and then install EK serial as well so EK CTL is a command line utility for you know like performing any any task related to eks Cluster okay so let me go ahead and then install that as well so it is installed and then and this is a version okay so I'm not worried so much about the version that's totally fine very good right I think we took care of all the CLI installables and the next thing is we also need to have Docker install as well so I'm going to directly use this command the reason why we have to install Docker is obviously right so if you look at this diagram we need to build the docker image for that you have to install Docker inside Jenkins very good so Docker also installed you can verify where the docker is installed or not very good Docker is also installed as well perfect so make sure Jenkins have proper permission in order to perform Docker bills that is really important okay so we have to add Jenkins user to the docker group okay and then I'm going to restart Jenkins service it's going to take a few seconds and then let's reload you know system Daemon files and then let's stop and restart docker and then you can also check the status as well real quick there you go very good so Dockery is running perfect so so far so good okay and then of course we also need to install you know Docker plugin and Docker pipeline plugin most importantly the docker pipeline plugin search for docker and we are going to install Docker and then Docker pipeline plugin perfect that's it let me go back to the instructions we also need to have ECR repo created okay I already have ECR repo Creator here if you go to AWS console ECR so creating ECR repo is not a big deal uh you know what let me do one thing let me delete this one and then I will create a new repo okay it's not a big deal okay so go ahead and create repo so this is the report I want to give so make sure this is private you don't want to make it public so that's it right click on create repo so that's it our repo has been created so this is where we are going to upload our Docker image from Jenkins pipeline perfect and then of course Docker file is already there so if you look at my source code we already have a Docker file perfect okay and then the namespace needs to be created inside ecase cluster but for that we need to create a cluster okay so if you want to create a cluster you can click on this particular link so I have provided instruction here on how to create eks cluster but I am going to leverage uh EK CTL command in order to install the or in order to create the cluster it's pretty straightforward so if you see here we also need to have IM role with administrator access okay because we are going to access AWS Services especially the kubernetes services like eks service right so if you want to create a cluster you are easy to instance needs to have proper permission so let me see here okay so let me go to ec2 the Jenkins ec2 okay let me see what is the IM role this has okay so I have this one but I have already created uh you know I am roll okay update I will show you what is the policy that has so if you go to ec2 instance click on security click on IM roll that will take you to your IAM and then you can clearly see that what is the policy that I am role has wonderful so we need to have this policy attached very good so far so good okay um all right so why don't we go ahead and then create the eks cluster so let me scroll down so I'm going to change into Jenkins user here okay and then we are going to create a eks cluster with two worker nodes okay so this is the command you see here right so in case it will create cluster so this is going to be the cluster name and then I want to create under us ES1 region and then this is the manage group name and then I want to you know create with two worker nodes and then this is a sizing for the worker node okay all right let's copy that command go ahead and then execute it so believe it or not this will easily take um you know 12 to 18 minutes or even even slightly longer so what we are going to do so while we are waiting for the cluster creation is happening so why don't we go ahead and then start looking into other things right meaning so if you look at this diagram yes the cluster creation is happening in the background but what we can do though we can still go ahead and then create a Jenkins Pipeline and then you know that can do some of the work as well right and then we will also create a Helm chart as well right so why don't we you know go with that right why don't we get started on that okay so let me go back to the instruction here let's see here right so if you see here uh we need to have Helm chart created okay so I have already downloaded or I have already what configured my visual studio code in my local machine if you see here so let me perform GitHub so this is my code okay so this is my code you can actually see here so this is my you know remote repo right so that is actually nothing but over here right so this is my repo so this is a springboard application which we are going to uh you know dark arise and then build the docker image and then you know this is what we are going to use right in order to deploy into eks cluster uh so we are going to use Helm chart so we need to First create the help chart okay so help is nothing but it's a package manager for kubernetes using help you can easily manage all your micro Services deployment inside kubernetes cluster why because you know when you're dealing with several micro services you may have to uh you know like you may have to create lot of kubernetes resources right you have to you know prepare for the deployment Services uh secrets you know service accounts and whatnot right so when you are leveraging help you can easily manage the deployment of you know all your kubernetes objects okay so this is where you know we are going to use Helm uh but but the best way to get started is so how do you how do you manage all those resources using help you need to create something called Help chart okay so how do you create a home chart so this is a command okay so what I'm going to do I'm going to go into my machine where I have already downloaded so in my machine also I have install Helm you see here I have already installed Helm in my local machine as well okay so what I'm going to do I'm going to first create the helm chart okay so how do you create a home charge very simple just say Helm create and then just give a name for the chart you can give any name but I want to give my chart there you go you see here right so now it has already created a chart folder here do you all see here and then if you want to see what is inside the chart you can use the tree command right so this has created Helm chart with all these files okay so that's the great thing about Helm right it is going to create all this template for you all you have to do is you know configure these files that's all we have to do okay so now uh there are few files you know we have to modify so let me open up values.aml file so if you see here okay if you see here this is where the image is mentioned right so this is nothing but from where you know we are going to download our our image okay so since we are going to upload our image inside ECR so we have to provide that image path okay so what I'm going to do let me go inside my ECR foreign so if you see here this is the URI so copy that URI and I'm going to replace that over here you see here right and then I'm not going to use any tagging since we are going to build the tag dynamically and we are also going to download the docker image from here from ECR dynamically we are not going to provide any tag we are going to override this from the Jenkins pipeline so just leave it like that and then scroll down and we are going to use load balancer so I'm going to type service type as a load balancer perfect so that's pretty much over there very good so let's save this and then let's also go to the templates folder and look for deployment.aml file so everything let's see if everything is good uh let's see here since hours is a spring boot right so you need to change the container port to 8080 so make sure you change that also perfect so let me save this perfect right so these two files needs to be modified so we took care of that okay since I have created the helm chart locally so what I have to do I need to you know add commit and then push into GitHub but before that let me make sure I took care of everything here so this is my instructions here I think we took care of everything as per uh you know instruction provided in my website very good so what I'm going to do I'm going to go ahead and then perform git status now okay so we have created this a chart folder let me go ahead and add it and then I'm going to say git commit minus M I'm going to say created my chart for my springboard app okay and then let's go ahead and perform git push very good so if I go inside my GitHub click on refresh there you go guys you all see here so this is our Helm charts right second chart with all the templates and everything very good and then of course if you want to verify your changes there you go you see here so this is from here it is going to download the docker image right from from ECR so that's a reference here okay perfect all right so what is the next thing so we took care of that now let's go inside Jenkins let's make sure we have all this thing configured right since this is a springboard which is a Java based so we have to first ensure that we have everything especially like you know we are going to use May 1 we have to make sure that you know Maven is configured here there you go you see here so I have I have already created this entry here okay so we are going to use Maven 3 very good let me go back to the instruction here and then yes we also need to create this entry as well but don't worry we will do that later because currently the eks cluster creation is still happening in the background there you go still it is going on so what I can do though is let me move forward here right so at least what we can do we can still go ahead and then you know create a Jenkins pipeline so at least what we can do we can check out the code build the jar file build the docker image and then we can at least what do until here we can also push the docker image into easier as well right so why don't we go ahead and at least get started on that so let me go to my dashboard Jenkins dashboard so click on new item so I want to create a pipeline so I want to create my helm uh you know deployment I'm going to say my Helm kubernetes deployment job okay so that is the you know pipeline job I'm going to create click on Pipeline say okay okay so pipeline got created now we can go ahead and then configure so let me select this option called hello world so this is going to give us the basic template so I want to first check out the code okay so we need to have a you know pipeline code to check out so click on pipelines and tax so click on checkout from Version Control okay so repo URL so this is actually a public repo okay so feel free to Fork my repository and then make changes okay so I'm going to uh you know check out from here since this is a public repo you don't have to you know provide any credentials uh what is the branch name the branch name is master so let me yeah it's already have it click on generate pipeline script there you go so this is the code for checking out code from there perfect apply save let me just make sure everything is working at least that particular stage is working before we move forward there we go very good so we were able to check out the code from GitHub let's move on to the next stage so since this is the spring boat right so if you look at the docker file you need to have if you see here right we need to have this springboard jar file being created okay okay and then of course using that you know we are bringing up the application isn't it we are copying the springboard app inside the container and then we are we are bringing up using this command okay so we need to create this jar file so if you look at the palm.xml file we have all the all the you know entries over there right so if I scroll down so if you look for the final name so that is going to be the name of the jar file okay and then if you also see here the packaging type okay so that's the form.xml file okay perfect so let's get started here right so let's go ahead and create a next stage now so we are going to create a next day next stage called build your file Subs block okay so now we need to use Maven so I'm going to since we have already mentioned that you're gonna go ahead and say Maven clean install that's it apply save so that should take care of you know building that jar file let's see so the jar file has been successfully built we could we could see that here as well if you go all the way down you'll be able to you know see that there you go the jar file has been created very good so why don't we go ahead and you know create the docker image as well so let me at the next stage here I'm going to say build image steps block and we are going to have script blog as well okay and what I'm going to do I'm going to create a environment block here and then I'm going to declare a variable called registry because this is where we are going to upload our Docker image that is actually nothing but ECR entry so go to ECR copy this and then paste it here okay and then here I'm going to say Docker dot build registry right okay so what I wanted to do as well we also need to tag the docker image as well so you know so so it's better to store that in a variable right so let's do this let's do like this Docker image equal to this okay and then we will use like that okay so we will just tag the docker image so this is the build number this is actually nothing but you know Jenkins predefined a variable okay so it's going to have uh it's gonna tag with the build number okay let's click on Bill now it is in the process of building the docker image and then you will also see tagging the docker image as well very good there you go you see here so we were able to successfully tag the docker image with the build number which is our build number is three so this was able to tag it wonderful very good so the next step would be go ahead and then upload the docker image into ECR so I'm going to write the next stage so I'm going to say push image steps block and script block so we are going to push the docker image inside ECR so let's go to ECR okay so this is the repo click on it and click on view push commands there you go guys you see here so we can leverage this this Command right so we are going to use AWS CLI so if you remember we have already installed AWS CLI inside Jenkins so that's the reason why why you need to install awcli so I'm going to use this particular command for authenticating okay so this is going to help you to authenticate inside your ECR and then I'm going to perform the docker push command because we have already built it we have already tagged the docker image all we have to do is you know push the docker image okay so what I'm going to do so you can also copy this command as well as one of the same so let me copy that there you go you see here and then what is account ID this is my account ID that's my account ID okay that's it right so whatever we have tagged it that image will be posted here right I mean you know using this command that image will be pushed inside ECR okay so why don't we verify this right I think everything is good let me make sure okay good apply save click on Bill now so far so good very good right and of course we can confirm that right now click on refresh here wow look at here guys so this is the image tag see I'm not using latest tag using latest tag is not recommended you always want to build your Docker image dynamically using your image tag right so so make sure you you do it there are many ways you can you know build your document dynamically but I'm using build number here wonderful all right so so far so good all we have to do is you know doing this Helm deployment but for that we need to have our ecase cluster configured wow see here guys it's done cluster creation is done perfect so why don't we go ahead and then query the cluster so Cube CTL get notes when you do that there you go guys so we have got two worker nodes uh so that is nothing but you can see that over here go inside ec2 console there you go guys look at that so that's our worker notes right wonderful wonderful okay so we were able to create that and then if you look for parts obviously we don't have anything deployed so nothing is there right so now what we have to do we need to First create the namespace correct we need to create the namespace so let's go ahead and then create the namespace okay and this is the namespace I want to give Helm iPhone deployment again you can give any name there you go so namespace got created and then if you want to know the namespace the list of namespaces there you go so we were able to see all the namespaces so this is the namespace where we are going to deploy our springboot application wonderful very good so so far so good we created the namespace as well so everything is good all we have to do is go to Pipeline and then use Helm command in order to do the deployment all right so before I do let me go back to here let's try to perform some Helm command so you can use this command Helm list so what this will do is this will list all the you know all the what releases in the default name space but if you remember we have created a namespace called Helm deployment okay so when you do that obviously we didn't install anything so you don't see anything right we have you know we have not done anything here so you don't see anything so that's totally fine okay but how are we going to do it okay so if you look at this command we are going to perform Helm command okay so we are going to use Helm upgrade okay so this is actually nothing but the release name and we are going to use this install command and then here we have to mention our chart folder right so if you remember we have already committed you know all the like chart information all the chart entry everything we have committed here right okay so all the chart information everything is under my chart folder okay and then this is the namespace so remember we have created a namespace and then most importantly we want to pass this image tag right so this is the image tag so what help me is going to do it is smart enough to know that okay so you want to install this help chart since we are passing that image tag dynamically this will be overridden here right okay and then it will go ahead and then download the docker image from ECR dynamically and then it will go ahead and then deploy okay very good so why don't we why don't we do that right so let me copy this particular command let me go to the pipeline first let me go here configure let me first create that stage we need to write code for creating the stage okay so I'm going to say stage I'm going to say Helm deploy okay steps okay we also need to have a script blog as well and then we are going to use this command okay I can copy this and then we can customize it that's not a big deal so let's do that okay so like I explained so we are using you know Helm upgrade command okay and this is the release name okay uninstall command and then we want to install our chart so this is actually nothing but your chart folder name okay so if you have some other name you can give that over here over there that's not a problem and then this is most important that's the name of your namespace and then this is your Docker image so that's it right so click on apply save go ahead and click on Bill now let's see okay let's see wow see here guys it says that you know release does not exist installing it now and then this was able to deploy wow okay so how do you verify you know this was able to deploy so like I said we are going to use helmless command there you go guys you see here let me expand this little bit there you go you see here so this is the release name and this is a revision one and then this is the date obviously and this is the namespace okay so that's that's our deployment right and and status is very important it says that deployed and then this is our chart uh you know whatever the chart name right wonderful and then how do you see all the parts and everything so what we are going to do we are going to obviously use get pods right and then use the namespace minus M film deployment okay wow there you go guys you see here so that's our part isn't it and then the way we are exposing is using service so let me go out and then get the service as well wow you see here guys so this is our service name and then of course we are exposing through uh load balancer URL and then if you want to see the Pod logs right let's let's also go to pod okay let me say Cube Ctrl describe part and then this is the part name and then this is our namespace name there you go you see here it say that successfully assigned created and whatnot right so everything is running right so everything is running right now wonderful so let me go back to survey so this is my load balancer URL so just copy that all you have to do is go to the browser try to access it it's going to take few seconds wow look at here folks so this is the output what we are expecting right look at that okay so if you want to make a code change right so what you can do you can go inside springboard application let's say I want to make some code change so I'm gonna you know modify in in here right here I'm gonna say uh instead of hello let's say I want to say Audi scenarios okay perfect so why don't I I know Commit This I want to say triggering bill and Jenkins if you want to configure web books feel free to do that but I'm going to manually run the Jenkins pipeline this is just for demo so what I was talking is if you want to configure web books you can go here right you can you can trigger through webbooks and whatnot that's not a problem there you go let's see so I made the code change wonderful so look at the revision two right so if I go back here if I say there you go so we see revision two okay so it's deployed okay very good so if you want to see the parts there you go see 19 second right so since we built the docker image dynamically it was able to detect the code change and then it was able to push the code change right it is it has created a new part very good and then if you want to see the output just go ahead and then refresh it wow look at here folks we are able to see our code chain awesome right so that's how you can deploy your springboot application inside kubernetes cluster using Helm and Jenkins pipeline so before I let you all go last but not the least so it is also very important that you need to clean up your eks cluster okay so don't forget it if you leave them running you will be really charged so perform this particular command in order to clean up all the resources you have created under eks cluster so this is the command Okay so eks ETL delete cluster perform this command so of course this is going to take maybe three to five minutes in order to gracefully delete the eks cluster so that's a good practice all right so yeah so let it run that's how you create a cacd pipeline in order to deploy your springboard micro Services inside eks cluster using Helm and Jenkins pipeline thank you for watching this video
Info
Channel: DevOps Coach
Views: 18,873
Rating: undefined out of 5
Keywords: EKS Cluster Tutorial Setup, Create CICD pipeline for Microservices Deployment to EKS cluster, How to Automate Microservices Deployment to EKS cluster using Jenkins pipeline and Helm Charts
Id: Ojb9Rh0BcvA
Channel Id: undefined
Length: 37min 10sec (2230 seconds)
Published: Fri May 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.