Deploying Spring Boot on AWS EKS (Elastic Kubernetes Service ) Tutorial | JavaTechie

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone welcome to Javi in today's video we'll be diving deep into how to deploy a spring board application on AWS e or elastic kubernetes service okay all right at high level AWS e provides a scalable and managed kuet service and that allowing us to easily deploy manage and scale containerized applications using qties if you are a developer looking to scale your application efficiently then Q is the goto solution and when you pair it with AWS eks the process becomes even more streamlined but don't worry if you new to all of these we'll break down the steps and by the end of this video you will have a spring board app up and running on your AWS e okay so without any further delay let's get started [Music] but before we jump into this deployment process if you new to cuetes and AWS then I will highly recommend you to check out my playlist on cuetes and AWS in that series I have provided clear explanation for each and every concept so without having basic understanding of these two technology this tutorial May cannot help you so feel free to pause this video take some time to go through this playlist and return to this tutorial when you feel prepared okay all right now let me walk you through the steps of deployment at very first step we need to create a spring boot project next since our goal is to run this app in a container let's dockerize the spring boot app or in simple word let's create a Ducker image following to that since we are utilizing AWS as our Cloud infrastructure let's push our image to ECR ECR stands for elastic container registry we can keep the image in Docker Hub but since we are using AWS let's utilize its services so that we can perform the seamless integration with other AWS Services okay fine next Once the docker image is prepared the next step is to deploy it to the qes that's simple isn't it just create the deployment and service object then just expose it so that it will deploy to the cuetes that is what the simple steps we follow right but here we don't want to take the heck of setting up our own kubernetes environment rather we leverage that using managed kubernetes service provided by AWS that is e case okay so I believe we are clear with the flow now it's time to see it in action so whatever the steps we have discussed we'll go through step by step but before we proceed further you must have these three setup on your machine first you should have an AWS account and you need to install the AWS C and qctl and you should have Docker up and running on your machine okay don't worry I'll share the link of this installation steps in video description after successfully installing these mention tools or software we are ready to proceed to the next step in our deployment process okay so the first thing we understand we need to create a spring board project so let's go to the intellig idea I have created one small hello world kind of spring boot project it having one endpoint SL greetings and it will return this particular string okay this is what we want to deploy to the AWS e so if you'll go and check in the pom.xml we are using the latest version of springbot 3.2.0 and jdk 17 and then we don't have any additional dependency apart from web and Lum book so we are good with the step one that is creating a spring board project now next we need to create a Docker image so to create the docker image we need a file called Docker file okay so first what I'll do I'll just specify the project name I mean I'll just want to generate the jar with my specified name so I'll just Define your final name then I'll name something like spring boot then just update it next I want to generate the jar first then I can give that jar to convert it to the docker image using Docker file so first let me run M and install so we can see here build is suceed now if you'll open the target you can find the jar name with your specified name here okay that's great now let's create the docker file so I just need to create the docker file in the root directory just create a file then just Define the attribute here let me Zoom this for you so I'm using the open jdk 17 and I'm specifying where is my jar so my jar name is spring boot e case correct so let me copy this name and also I'm exposing the port to 8080 that is what the container run my image and I am just giving the command to execute my jar so the jar name is spring board hypen e okay that's it now next let's create the Ducker image that is what we have defined in the step two right so just go to the ID make sure you should run your Ducker desktop on your local machine to create a Ducker image so just go to the terminal you can Define Ducker build iph T and what is the image name you want to keep keep just enter it so we got some error what is the error okay so in the step to I mean in the docker file we have defined it twice let's remove one jar Do jar now let me rerun it it will take few second to create the image yeah you can see here image is created now if you'll check in your Docker images you must find these images better I will directly check in the terminal can you check here if you'll scroll up yeah here is the image also we can see the image here also let me filter it yeah can you see here spring boot e less than a minute so you're good with the step two now the next step we need to push that Docker image which we created to ECR so is stands for elastic container registry this is one of the service given by AWS to to store your images so in my AWS playlist I already explained about this ECR and also we did couple of cicd pipeline using ECR you must need to check the video to get more knowledge on ECR okay so now next step push Docker image to elastic container registry so just go to your console AWS console if you don't have a account just create it once you have a account you can search your ECR elastic container registry just go here now this is the homepage of ECR you can see the option create a repository just click on get started and then make the visibility to private and just give the repository name I'm giving spring boot iphs same name then nothing to change here just click on create repository yeah so you can see here the repository is created now to this repo we need to push our Ducker image so now we cannot see any images here right so to push the docker image to this ECR you can find the command handy in this particular page itself so you just need to execute this command so first copy this then go to the terminal or even you can run it from here let me do it here so nothing I'm just trying to log to the EC through the aw CLA and this is what the username and password just enter it yeah can you see here login succeeded now what is the next step just build your Docker image which we already built so you can skip this but if you'll build it again it will pull from your Ducker engine okay just run it again so you can skip this that is optional now what is the next just tag the just tag the image with the latest okay so just copy this and then let me me clear this simply execute it cool now the last step we need to push it to the ECR so just copy this particular command and Trigger it here so let's wait it to complete so this same succeed now let's verify this in our ECR just go to the browser just close it now if I'll refresh this I can see my images here with the tag latest and these are the images so I need to copy this particular URI for reference so just keep this particular URI for your reference fine so we are good with the step three so we create a springboard project we dockerize that image then we push that image to the ECR now the next step we need to pull the image from ECR and deploy it into the eeks which is plastic kubernetes service so it means we need to do the setup of e to push the image from ECR correct that is the last step is pending so first let's do the E setup to to do that first we need to create one cluster in EAS so let me duplicate this particular page now if I go to the services and if I filter eks you can find here elastic kubernetes service just open that so here you can create the cluster by click on ADD cluster or create cluster you can do it from the UI okay but there is also a option you can use the E CTL tool to create the cluster and to do the basic setup in your eks okay so in this tutorial I will not go through the UI steps rather I'll trigger the command using eksctl basically this EK CTL is the common line utility for managing your Amazon eks cluster it simplifies the process of creating updating and deleting your eks cluster with a simple command so I'll prefer to use that so what I'll do I'll will open the terminal then I will trigger the command to just create the cluster using e CTL utility so let me Zoom this for you so the Comm I want to trigger is the simple one eks CTL create the cluster with this name JT cluster then this is what the kubernetes version I want to use 1.28 and no type t2. small that is what the E2 instance I want to use and in which region you want to create your cluster that is Us hyen East hyen 2 that is what the region I am using to create my e cluster okay so this is the simple command so let me me change the name of my cluster we'll give some meaningful name so I'll change it to Java cluster okay now just enter it it will take 12 to 15 minute to create your [Music] cluster great so you can see here e cluster Java and the name of our cluster in this particular region is ready to use can you see here and it almost took 14 minute we started at 45 and it completed on 59 okay that's fine now to verify that the cluster is created go to the browser and just refresh it we can see the cluster here right just click on this cluster name then you can see here lot of configuration information about your cluster okay since we have created using the common line tool it created all the required configuration for us that's fine next we need to update our local Cube config file so that from our local command it can connect to our this particular cluster so for that what you can do go to the terminal let me clear this then just update your C config file with your cluster so that it will load all the necessary configuration required from your local to connect to your e just enter it okay update the context with this this are the cluster and it update our Cube config file now since our cluster are up and running the next step is deploy our application to kubernetes Cluster which is EAS so to deplay any application to the kubernetes is we need two thing deployment object and service object and these two object we usually create using the yml configuration okay in application we specify the configuration to tell to the kubernetes what is the image you want to depl to the cluster and which kind of service you want to expose okay so let's define the kuet Manifest file which is nothing service. yml or deploy do yml so let me go to the project then what I'll do I'll just create a file call K8 s. yl then here I just need to define the deployment and service specific configuration so just add it this is simple guys okay in my kubernetes playlist I have explained each and every configuration details so just have a look I will share the link in video description you guys can understand what is the the deployment and what is the service object in kubernetes so here nothing I'm just telling in the deployment object this is what my deployment name and this are my label and here I'm telling the number of parts will be three I want to create the three parts of my application so the replica we have specified three and the container Port is 8080 now here you need to tell to the given itties which image to run in the E cluster so if you remember in the steps we have pushed our image to ECR so we need to give that URI to run or to pull that image in our cuetes and run it in the E okay so see it's very simple we are not using our local kuties we are using the E which is the cenes instance or Services given by AWS okay so it's very simple just go to the browser then just copy the U fine then go to your code and tell to the cuetes to pull this particular image from the ECR and run it on the E cluster now if you come here the service I have defined name of my service and the selector label I have specified the same for deployment and service and then I have specified the port 80 Target port 8080 and the service type I'm exposing load balancer you can also try with the node port or external cluster IP but here I'm using the load balancer okay so once you have this file then you just need to apply this manifest file to initiate the deployment and service object deployment okay the simple steps what you can do so first let me navigate to this particular directory this is in CD desktop javate tech key code then I'm inside spring boot hyen e great okay now if you will do LS you can see the yml file right k. yml file so simply just apply it Cube CTL apply hyphen a what is the file name you want to apply where it contains the deployment and service object that is ks. yml right just SL it so in few second you'll see it will start service object and deployment object can you see here it created the deployment and it created the service now the number of parts we have defined three so to validate that first let me check Cube CTL let me Zoom this for you get service so you can see here right my app hyphen services this is this is what the service name and type load balancer and this is what the external IP using that we can able to access our application but before that let's validate the ports keep CTL get ports it should display three parts great can you see here there are three parts and all the status is running there is no error fine so we good here okay so now what but how how we can access our application let me get the URL this external IP so simply let me clear everything I just need to get the service so this is what the URL right let me copy this particular URL then go to the browser and hit this particular endpoint it will take few second so finally we can see the 44 API specific error because we have not specified the endpoint URL so what is that greetings that is what we have defined right so if you'll go to the main class the URL is SL greetings just paste it here enter it can you see here the output welcome to javat Tei and your app is deployed to the AWS e case that is what we have just returning from our end point now if you'll do validate again this are the cluster and if you will filter here since we have exposed our service as a load balancer you can find the load balancer instance which is created by the this eacl command can you see here this is what the service we're exposing right so AWS created the load balancer for it and also if you'll check the E2 instance the instance is running that is what we have defined right while creating the E cluster we have specified that particular command to use the E2 instance of T2 do small that is what the instance is running here so if you'll see here these are the instance so that's fine we are not going to focus on this configuration when we try with the UI that time I will explain what all basic configuration is required to create one ec2 instance okay so we are good we are successfully deployed our application to AWS EK eks is nothing managed kuet service running on AWS itself okay that is the simple step now the last step what you need to do you need to tear down your cluster or you need to delete your cluster because this will charge something I mean a big number it will charge so it's better if you are using it for the learning purpose once you tested your scenario if things are working it's good to delete the cluster so the command is very simple let me delete the cluster we verified with this particular external IP we're able to access the endpoint right so to do that to delete the cluster what I can do Cube CTL delete cluster name of your cluster what is that javat hyphen cluster just enter it again it will take 5 to 7 minute to delete your cluster what is that the server doesn't have a resource type cluster okay so yeah the mistake is I'm running it using the CU CTL but that is what we need to use the ekl okay ekl delete cluster javate key so it initiate the request to to delete the cluster so again it will take few second so we are good I believe okay so this is how we can deploy our application to AWS eks so all the required resource what we have discussed here I'll share in the video description also I will share link of my medium blog where you can find each and every step okay do let me know in a comment section if you guys have any doubts that's all about this particular video guys thanks for watching this video meet you soon with A New Concept
Info
Channel: Java Techie
Views: 31,548
Rating: undefined out of 5
Keywords:
Id: mVSFHgItaa4
Channel Id: undefined
Length: 22min 34sec (1354 seconds)
Published: Fri Feb 02 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.