Deploy Springboot Microservices to Kubernetes Cluster | Full Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey what's up everyone and welcome to daily code buffer in this video we are going to see how to deploy our springboot microservices into kubernetes cluster so in the last video about the springboot microservices architecture there we have built an entire microsoft architecture with few of the micro services and few of the other components as well so today we are going to deploy all of those components into a kubernetes cluster so let's have a recap of what we have built in that particular microservice video if you have not seen that video i will link that video in the description below you can check that out as well so let's go ahead and see what we have built [Music] i'll just open the github account and here you can see that we have built the few of the micro services over here that is user service department service where we will be able to save the user and we will be able to save the departments we have added the service registry where all our micro services will be registered so we can leverage the service registry to interact with the micro services so we have created the api gateway that is a cloud gateway from which all the apis will be called from the internet from the external world and internally everything will be called after that and we have also created a cloud config server where we can externalize all our configuration and we can save in one place so we are leveraging the cloud config server as well and we are also using the histrix so to make the microservices resilient we are using the histrix over here so we have added the historic dashboard as well over here and we have implemented historics in our cloud gateway microservices internally we are also using zipkin and sleuth to do the distributed phrasing over here so all these components are already been built and you can check that video to create the microservices by your own once you have done that we can continue from this video to deploy all these components into a kubernetes cluster now there are few of the prerequisites to continue with this video i suggest you to go through all those components first and then continue with this video first thing is you should be familiarized with the docker and kubernetes components i'm not telling you about the export level but you should be aware about what docker is and what kubernetes is and what are the different components those basic understanding you should be having so it will be easier for you to follow this particular tutorial i have created a video for docker and few of the components of kubernetes i will link all those videos in the description below so you can check all those videos out so it will be helpful for you guys now this is all about the prerequisites about the different technologies now in your machine docker and kubernetes should be installed in your machine i have a dedicated video about how to install docker in your machine so i will link that in the description below you can check that out and i also have a video how to install mini cube cluster in your machine so you can check that out as well now with all those things said we will do our configuration so that our application is ready for the kubernetes deployment okay so our application is ready to deploy in our kubernetes cluster so we have to do few of the changes we have the configuration that we will do let's discuss our architecture and what we'll be doing on top of it okay so you can see that this is our architecture we have a user service we have a department service and both the services are connected from api gateway and user can access the api gateway directly we have a historic dashboard where we can see how our service is behaving what is the resilience ratio and everything in our history dashboard and everything is connected to our service registry so all these apis are registered to our service registry so we can have a look what all these services are attached to our service registry and we can manage them we also have a zip code server and we also have a config server which will be connected to our github repo where we will be storing our configuration files and it will serve the configurations to our entire application now to make this component is ready what we have to do is we have to run all those components into a container right so to create a containers out of every application we have to implement docker so what we'll be doing is we will be adding the configuration in our application so that our application can create a docker image of it so what we're doing for all the application we will be using the docker file maven plugin which is from the netflix which will allow us to create the docker images out of the docker file so we'll be creating a docker file also for all of these components so that's the one thing and we will be pushing all those images which we have created to our docker hub so currently if i show you over here this is my docker where we don't have any images over here so we will be pushing all those images of all the services to our docker account now with that thing done like creating all the docker images and pushing all those docker images to our docker hub registry we have to use those images in our kubernetes configuration files so we have to create the kubernetes configuration files for all these components so that we can apply or we can create all those resources all those components into our kubernetes cluster as i said earlier you should be aware about the basic kubernetes resources and components so it will be easier for you to follow this tutorial now starting with the basic one that is our user service and department service what we'll be doing is we will be creating the deployment component and the service component of kubernetes okay for this two particular services so a user service will be deployed using a deployment component and for that particular deployment component will be creating our service component that service component will allow us to connect through different components different applications okay so that's how kubernetes works so we'll be creating the services as a cluster ib types so that means we can leverage all those particular services internally because this particular user service this particular department service should not be exposed directly to the outer world to the internet because for that we have a api gateway so this user service this department service should be created using the cluster ip that is the internal ip so there are different types of services available in kubernetes that is node port cluster ip load balancer and headless services we will be using all of them over here and you need to understand how we are using all those services and how they are useful as our user service and department stories are to be called within internally okay we will be using the cluster ip so those particular applications are not exposed outside this particular api gateway so for the api gateway api gateway will be the responsible for traversing all the traffic from the external world to our kubernetes cluster so for that we will be creating the load balancer service so we'll be creating the deployment for this api gateway and on top of that we will be creating the load balancer service so load balancer service is nothing but a service which allows the external traffic to our kubernetes cluster and for the historic dashboard we can create the node port service over here so notepad service is also similar to the load balancer service which allows the external traffic to the kubernetes cluster so the key difference is notepad will enable the port for a particular virtual machine or a particular node so if you have multiple nodes for all those nodes that same particular part will be open to access all the traffics through the kubernetes cluster so that's a key difference between load balancer and node port if you are going for the production grid application where you are allowing all the traffic from external or from the internet to your kubernetes cluster that should be one api or there should be one service that is a load balancer service along with the ingress component so that's the different component we'll be using for the service now the other one important one is a service registry so for service registry we won't be using the deployment and our normal service we will be using a stateful set now what's the difference between deployment and stateful set and why we are going with a stateful set for this particular service registry so one thing to understand over here is deployment and state full set are both similar resource management or component management in kubernetes cluster where it will manage our parts internally okay stateful set also will be creating the pods and deployment also will be creating the ports but stateful set is particularly used for your stateful applications like your database like your registry where you have to maintain all your host information or your state of the application right so for those particular cases you will be using the stateful set so for this particular example service registry we have to maintain the host information because whenever you are creating the deployments your pods will be created using the dynamic name your pod name will be appended with the dynamic hash value so for this particular service registry we don't want that we want a particular host name so that we can give that hostname to our application to all the other application so that all those particular clients can connect to service registry with that particular host so to get that particular host name uniquely we are using the stateful set now stateful set doesn't work alone it has to be created using the headless service now what is a headless service headless service is just a similar normal service without a cluster ip now whenever you are creating a service an ip address will be assigned to it okay but when you create a headless service an ip address won't be assigned to it it will create the end points internally to expose the pod to the kubernetes cluster so we want the entire dns name hostname for this particular service registry so we can access or we can assign that value to all our clients so that they can register to our kubernetes cluster now to understand what i'm saying over here that might be difficult but keep this particular point in mind when we are doing the coding for this particular thing when we are doing the configuration you will be able to strike this out like okay this is the particular thing why we are using this stateful set and why we are configuring that way so when we are creating this headless service and a stateful set for this service registry we can access that particular part information using a particular format so this is a particular format you can access using the pod name and the replica index so whatever number of replicas you give in the stateful set so suppose if you give one replica the replica index would be zero if you give three replicants would be 0 1 and 2. so accordingly you can give this particular replica index dot service name that you create that's that this service name is the headless service that you created and default.svc.cluster.local using this particular name you can access the particular pod from that particular state full set so this is the particular thing we'll be using in our application to connect to service registry and all those clients to it so this is what everything we are going to build so we'll be deploying entire all these components into our mini cube kubernetes cluster so we'll be creating all those aml configuration files for it and we will be deploying everything so now let's go to our application and let's do the configuration for our docker images and docker configuration to create the docker images and to push those images to our docker registry so here you can see that i opened all this particular micro services that is user service service registry history dashboard department service cloud gateway and cloud config server so let's open one of them okay and here you can see that this is our palm.xml file this is our application.yaml file and the normal controller service tao repository layer and everything if you have seen my earlier video we have done all the all the things over here okay now we will do the configuration to create the docker images so first of all we need to add the dockerfile plugin in our pom.xml file and then we have to create the dockerfile so let's add the plugin over here first okay we'll go to the pawn.xml file we'll go to the build over here and there we will be adding our plugin okay inside this plugins i will add this plugin over here this plugin is nothing just the docker file maven plugin over here from spotify okay and here in the execution environment we have given the build and push so it will build the images and it will push the images to our docker registry and in this configuration we need to give the repository name so here we'll give the repository name so my repository is daily code buffer slash user service will be the repository because this is our user service application and the tag would be the project version so let's go to the project version over here and this is the version let's just simplify it i'll just give 0.0.1 over here so this is a simple configuration that we have added over here and one thing you can see over here that we have added this particular dependency java x activation this is only when you are using jdk 9 plus otherwise this is not required and the other thing is you can see this stack we have added like use maven settings for authentication now why we are using this you need to authenticate to your docker app to push these images right so we will be giving all this configuration in our settings.xml file in your m2 folder now if you're directly logged into your docker hub or your registry using your command line then you can skip this particular line okay so that when you're building this that particular configuration will be used from your terminal otherwise you can add this particular tag over here use minimum settings for auth and once you add this you need to add the configuration in your settings.xml file so for the settings.xml file this is the configuration that you need to add so this is the settings.xml file and here we have added the server details over here in this server details we added one server that is docker.io because we are using dockerhub and you need to give your username that is your username and your password so once you give this information you are good to go so once once we give all this information what we need to do is we need to add the dockerfile so let's add the docker file over here i'll just create the docker file and let's add the docker file configuration this is just a simple thing from we are using open jdk 11 yeah arguments i am defining like jar file path will be target slash star.jar so whatever my jar file is created it is within the target folder that will be using it and will be copying that jar file to our particular image and this is the entry point that we gave over here that java hyphen jar command should be used to start our service and we are exposing nine double zero two port as i'm using nine double zero to port for this user service so this three configuration that we need to add we added the docker file we added the docker file plugin in our palm.xml file now we need to build this if you currently go to our docker above yes registry you can see that we only have one particular registry that is docker published nothing else so what we will be doing is we will be executing this okay so let's open the terminal over here so we will just do mvn clean package will package our application and then we'll use docker file and then we'll use this docker file plugin to push our image to our registry so we'll just use docker file colon push goal so it will build and push it so let's see that okay you can see that it's building so it will take some time to do this will we wait for a few seconds to complete this thing you can see that image will be billed as daily code buffer slash user service 0.0.1 so this will be using in our kubernetes configuration so this this particular configuration is not done yet for this particular user service i'm just showing you how this particular docker file plugin will create the image and it will push to our registry once this is done we will move ahead to all this different configuration so let's just wait to finish this okay so meanwhile this is happening we will add the same configuration to all our different services okay so let's go ahead and do that we added in user service we'll add in our service registry so in this service registry we will be adding the plugin over here added the plugin over here the same plugin that we added in the user service and we gave the repository name as daily code buffer slash service registry we'll change the version also over here we'll just remove the snapshot over here to make it simple and we'll create the docker file over here new docker file this is the content from opengdk11 the same thing okay it's the same file that we created just the name of the jar file that we changed and we will be exposing the port 8761 as we are using 8761 port over here now let's add for the historic dashboard over here okay inside this historic dashboard we'll add the plugin and here we have added the historic dashboard over here daily buffer slash historic dashboard let's change the version over here to make it simple and we will load maven changes and we will create the docker file over here create new docker file i'm just copy pasting this thing because these are simple things and just reusing it okay so just open jdk 11 that's the same jar file i just named to histic dashboard jar file and we are exposing to port 9295 now let's do it for department service over here okay i'll add the plugin over here and here we are using daily code buffer slash department service let's change the version and we'll add the docker file now as we are adding the docker file in the root directory with the default docker file naming convention this plugin will pick it directly so the same code over here we renamed the jar file to department service and we are exposing the port that is 9001 over here now we'll go to the cloud gateway we'll go to the pom.xml file and we'll add the plugin over here here we'll say daily code buffer slash cloud gateway we'll change the version and we'll add the docker file again here and this is the cloud gateway docker file data okay we are exposing to port 9191 now the last one is cloud config server we go to the pom.xml file and here we'll add the plugin information and here we are adding repositories daily code buffer slash cloud config server we'll change the version over here and we'll add the docker file here as well so what we did we added the dockerfile plugin and docker file to all our applications now we already ran for our user service let's go ahead and see what happened there and here you can see that everything completed successfully right so here you can see that successfully built daily code buffer slash user service and it was able to push to docker i o slash daily code buffer user service push completed now if you go to our docker hub let's refresh this and here you can see that user service is created okay and yeah when you open this you can see that zero point zero point one version three minutes ago now we'll be doing this for all our services and before that what we have to do is we have to do the configuration for our service registry because currently we don't have anything that's a default configuration from the spin input so that's why we were able to connect earlier when we are trying in our local but now as we are deploying in our kubernetes cluster we have to give that particular configuration to all the clients and the service registry how to connect to each other so we will give that information so with this particular logic over here like pod name hyphen replica index dot service name dot default svc cluster local we will be doing the configuration so let's go ahead and do that so if you go to the service registry over here and go to the application.ml file and here you can see that it is just a default configuration over here so we'll give the configuration about what is the default zone and what is the service url to connect to so i'll give eureka instance host name equals to hostname.eureka and we will give this particular service url and default zone so we added instance.hostname over here and we have also added service url dot default zone so what will be the default zone so this particular variable is the environment variable that will be passing using our kubernetes configuration so i'm just doing this particular configuration like this particular default zone should come from the environment variable in just the service registry to show you how we can use the config map component of kubernetes for the other services you can also implement the same but for the sake of simplicity and the time i will just give the information directly for the other ones so let's add the configuration in the other services as well we'll go to the cloud gateway we'll go to the application.yaml file i will give the configuration over here so this is the same configuration that we added in the service registry but here we i am giving the direct url over here rather than passing from the environment variable so eureka instance preferred ip equal to true hostname equal to unica0 so here you can see that i am passing urecas 0 over here for the pod name hyphen replica index okay so my partner would be eureka so that's how we will be going to configure in our kubernetes cluster and here default zone you can see that we added the same way http eureka 0 that is pod name hyphen replica index dot service name my service name will be eureka when we create it and after that default.svc.cluster.local that is default.svc.cluster.local and our port information that my service registry is running on port 8761 slash eureka so this same configuration we will add in all the service so i'll just copy this over here i'll go to the department service application.dml file we'll add here as well in the config server then we'll go ahead and add in cloud gateway it's already done we'll go to the department service done we'll add in the historic dashboard as well we'll go to the application.ml file and we'll add the same configuration over here we will go to the service registry here we already added and we'll go to the user service go to application.yaml and we added this particular configuration so in all the services starting from user service registry service registry history dashboard department service cloud gateway and cloud config server now all of this have the configuration okay and in only service registry i have given this particular url to be fetched from the environment as everywhere i have given directly but we can leverage that config map which we are going to create and you can use that also over here so you can try it out by yourself that also now what we'll be doing is we'll be building and pushing this docker images to the service registry for all our service so let's do that we'll go to the user service terminal and we'll run this command again mvn clean package docker file push we'll go to service registry terminal mvn clean package docker file push and then clean package docker file push we will go to the historic dashboard go to terminal mvn clean package docker file push then we'll go to the department service mvn clean package docker file push oops and then clean package docker file push we are in department service right we'll go to the cloud gateway terminal mbn clean package locker file push and the same way we'll do in cloud config server as well mvn clean sorry mvn clean package docker file push now one note over here i am doing everything manually over here to show you what all things happens to make this particular depth all the services deployable in our kubernetes cluster now what all the things which are doing over here to build our services that everything can be automated using the ci cd pipeline so currently i'm just showing you everything over here manually but everything will be automated so with just one click of a button every process should be completed and your application should be up and running within seconds so just try to understand over here the different components and different processes that we use to make everything work together so we'll wait for some time to complete this process and we'll be back within few minutes now here you can see that the build is completed for this particular cloud config server for cloud gateway is also completed for the department services it's still running on okay so within some times it will be finished okay it's finished now you go to the historic dashboard it is also finished it was a service registry okay it failed over here let's see what failed we'll go to the user service and it's done over here let's see what happened in user service okay there are test failures okay let's let's just disable the test for now okay i'll just remove the test for now okay and let's run this again and then clean package docker file push so we'll wait for a minute to complete everything okay yeah you can see that that particular image is pushed now okay so let's go to the docker hub and let's see we'll go to the repositories again over here let's just refresh it and here you can see that all these particular repositories are here department service cloud config server dashboard cloud gateway user service all you can see that updated within 10 to 5 minutes over here now this particular images will be using in our kubernetes configuration now as everything is done over here let's go to the kubernetes configuration so let me just open the terminal over here and if you see docker images over here sorry yeah you can see that all these particular images are over here that we already built over here now let's check our mini q is running or not if you see that your mini cube is not running you can use the mini cube start command to start your mini queue service over here to start your mini cube cluster over here i have created a dedicated video on this how to install mini cube and how to work on the mini cube i will link that in the description below you can check that video as well so here you can see that my mini cube status everything is running my host is running cubelet is running api server is running and type is control plane as our minicube kubernetes cluster is running our docker is running we can go ahead and create our kubernetes configuration files and create our application into our kubernetes cluster so let's go to the visual studio and let's create the kubernetes configuration file so i'll just show one for you how to create a kubernetes configuration file rest will just copy paste and i will share all these particular files with you so you can check that out and you can do the configuration accordingly and also one note over here we are going with the minimum configuration over here there are lot more things that you can do you can go through the kubernetes documentation website and you can learn about more other components and you can integrate all those components over here so we'll just go ahead with the minimum configuration so it's easier to understand and get an understanding how everything is connected together and how everything is deployed together within the cluster so in our this kubernetes file let's create one user service dot yml file over here and here we'll be defining our deployment and service so let's create the deployment over here so you can install kubernetes snippet plugins over here in the visual studio code so it will be helpful for you to create the config configuration files so i'll just use deployment simple over here and you can see that the entire simple deployment is created i'll just use the apps v1 version my kind would be deployment so for all the kubernetes resources these four things will be always there what is your api version the kind of the resource the metadata information and the specifications of that particular resources so we will give all these details over here so i'll say api version this appsv1 kindness deployment metadata and name of my deployment is user service app and here in this metadata we will give the labels in this label i'll give my application name should be user service app over here and here replicas i will add one okay i need one replica in this template template metadata labels here in instead of editor vs code i'll just use app as user service app over here and here after this replica will add the selector with the match labels and labels should match with app that is user service app so whatever the specification we give over here it will match and accordingly all those components all those pods will be selected okay so we gave the selector over here and the template information now here in this specification we need to give the name of the container and the image information so i'll just give the same name over here that my name of my application would be user service app and here in the image we need to give the image name so whatever is available over here right if you go to the user service this is the name that you have to give user service and the tag name tag is 0.0.1 i'll just add the image build policy always so every time the new image whatever is there it will be pulled okay i'll give the ports information ports my container port is 9002 so what what is the port your application is running on so if you are if you go to your user service your user service is running on port 9002 so that information we gave over here now as our deployment is created we will create our service okay so we'll just create the service complete over here okay so these all things you can see that it's been auto populated using the kubernetes snippet so it's very helpful over here okay so we just use the kind of service api version is v1 metadata we will give we'll give the name as user service svc and in the specification selector we need to give the application name which application this should select so this is the application it should select and here type we will give as cluster ip okay so i will be creating the cluster ip type and if you don't define the type all as well okay default will be cluster ip so if you don't add that's also fine over here and here in the ports you need to give the port information and the target port so your target port is 9002 so this particular port is like on which port this particular service should be running so i'll just give 80 for http i don't want the name for now so i can just skip it over here okay but you can define the name as well if you have multiple ports i don't have so i can skip it for now and it will be okay so this is a simple kubernetes configuration that we created for a user service we just created the deployment where we have defined the name of this particular deployment and which particular application it should start so we just gave the labels over here in the specification we defined how much replica should create and the selector application we that we give and in the template we give the specification okay so yeah we provided the containers this container name we provided and the image information like this particular image should be used and this particular port it is running on now the similar thing we have to do for all of it except the service registry because for the service registry we will be creating the stateful set as i already told we want a particular name of the service registry in this particular format to be able to connect to other registries to uh sorry to other clients okay so i'll just copy paste the configuration for all the components and i'll walk you through it okay so let me just create department service dot yml this is for the department service where we created the deployment we give the name department service app we give the label and similar way specification we give that we want one replica and the name is department service app and in this specification containers we provided we want daily code buffer slash department service dot zero dot zero dot one image full policy always container port is nine 9v01 my application is running on 9001 so this is the deployment and for this deployment we created the service and the name we gave as department service svc and we gave the selector as department service app this service should select this particular application and we also gave the target port like this is the 9001 target for for this particular container and it should run on port it will do for config server dot yml the same information we have provided over here we created deployment the name we gave metadata labels and in the container we give images daily code buffer slash cloud config server.0.0.1 which you already provided from here okay cloud config server and for this particular image is running on 9296 so for that we created the service that the target port is 9296 and it should run on port 80. now let's create for the cloud gateway dot yml now this particular cloud gateway that is the our api gateway for this we should not be creating the service as a cluster ip because this particular api gateway is responsible to get the external traffic so for this will be creating the load balancer so this is the deployment where we are just using epi version kind is deployment metadata cloud all the same information that we give in all the other three okay the same information just the image name that we have seen and the application name we have changed only one thing over here is we define the load balancer type over here rather than cluster ip when you define the load balancer it will be an external service okay so we are defining the container port as 9191 and the target port is 9191 and it should be running on port 80 so this is the service that we defined over here now for the historic dashboard now this is the historic dashboard over here now for this particular historic dashboard we use the node port service over here just to get the different understanding how this particular things work doesn't mean necessary that for the history dashboard you have to use the node port you can use whatever is feasible draw the cluster ip or load balancer or ingress also directly you can integrate within the other service it just depends on what is the use case so i'm just showing you that we can also use the node port so that's why i will use the node over here so here in the type of the service we will be defining the node point over here and the target port will be defining 192.95 which is the port where this particular application is running on and we are exposing the port 80 for it this is the same thing what we did over here in the cloud gateway are in the config server everywhere so this configuration is very simple okay now we will see for the service registry we'll just define the service registry.yml file over here and here in this service registry what we'll be doing is we'll be creating the config map component to define the variable so that we can use that variable in our environment the second thing will be creating the stateful set so with that particular stateful set we will be deploying our service registry so that we can get the particular host name okay so that hostname we are using in our different eureka clients the next thing is as we are creating the stateful site we will be creating the headless service for it and on top of that we will be creating the service from which we can access that particular service registry so four components will be creating over here so this is just a simple difference that we are using in service registry rather than deployment we are using the stateful set to make sure that that particular hostname we got that we can reuse that's the only difference in the stateful set for this stateful application so for that purpose we are using it and for that stateful set headless service is required so we are creating the headless service headless service is nothing but the service without the ip address and it will internally create the endpoint to communicate and on top of that to actually communicate with that entire service entire pod and that service will be creating the service to connect to that particular pod and on top of that we are creating a config map to give this particular environment variable that we have defined in our service register if you go to the service registry go to the application.yaml file and here you can see that in the default zone we have provided the environment variable so for this particular reason we'll be creating the config map and that config map will be using in our environment variables there is also a component called secrets which is used for the credentials on all the other information which are restricted so for those information to store all those information like credentials and the database details and all those things you will be creating the secrets and that secret you will be using in your environment variable or wherever you are using it similar to what we'll be using from the config map so let's go ahead and use that as well so we'll be creating the config map over here this config map is very simple over here api version one kind is config map the same metadata information and the data that we want to pass over here i'll just give the name over here as config cm i don't want any labels over here i'll just remove it we need to give the data as a key value pair so i'll just give the return key value pair that is eureka service address is http eureka zero dot eureka 8761 slash eureka so this is the config map that we have created now let's define the headless service so this is the headless service that we have defined over here for the headless service also the kind would be service okay so we define the service over here the name in the metadata that we have defined is eureka so this eureka defines the service name over here that we have defined in our urecast service address this is the same one that we have to define according to this particular format that is this particular service name so we define this eureka and this eureka iphone 0 is the pod name iphone replica index so we define this particular name over here and this particular service this particular service should be having the label we have defined that this particular is of app eureka and in this particular specification we have defined cluster ips none this particular line defines that this particular is a headless service and in this particular ports view defined this service will be running on port 8761 and the name of the port is eureka and the selector app is eureka so we'll be creating the stateful set where we'll be defining the name of that as a eureka so that will connect to this particular headless service now let's create this stateful set okay this is the entire state full set over here you can see that api version kind metadata and spec these are the four things that we need to give over here so we are just giving this epa version has apple one kind is stateful set metadata name name of this stateful site is eureka we have defined the selector app urec over here and in this specification we need to give the service name this is the headless service that we created so we are giving the ureka name which we defined over here so that's the name we are giving so it will connect we want one replica and the selectors we give match label app is eureka and in the template information we also give the metadata in labels and this is the main part specification in this particular specification we define the containers how we define the containers in our normal deployment if you see the normal deployment over here in this particular specification we define this specification of this particular template where we define the containers similarly we have defined over here so in the containers we give the name of the container that is eureka so based on this the part names will be created the image name that we give is daily code buffer slash service registry 0.0.1 image policy always the port information how we define for others that is container port 8761 that's done now we want environment variables so this is where we define the environment variables with environment column and after that we need to give the name of the environment variable so this is the eureka server address that we have defined in our service registry eureka server address so that's what the name of the environment and either you can give the value directly or you can get the value from secret or config map here we want that particular value from the config map so we define value from value from and that we have defined value from config map key reference this is the configmap that we created and from that config map key reference we want and what is the name of the config map from where you want to get the key that you have to define that is eureka cm that's the name of your config map okay eureka cm so that we defined over here and in this key you need to define what is the key to get the value and your key is eureka service address so once you define this key you will get this particular value over here so we have defined key as eureka service address so that particular value will come to this eureka server and this eureka server address environment variable will be passed to this particular value default zone over here so this is what we have defined so we defined config map header service and the stateful set now i'll be defining the service so that we can connect to this particular stateful set so this is the service i'm giving the name is eureka i'll be the application name the labels as eureka selector as eureka okay for this this will be selected for this particular service type i have given as node report and the ports which is working is 8761 and it is exposed to port 80 so we can directly access this particular application now all the configurations are done so we configure our entire application in our kubernetes configuration files manifest files okay so how how all the applications should interact how all the different resources and components of kubernetes to be created inside our kubernetes cluster so everything is defined over here now now just with the one command everything will be deployed so let's see how to do that so this particular configuration is the key part of everything that we are doing how every component has been interacting with each other it defines on this particular manifestation file that you create so if you have any doubt regarding this what we did over here you can reach me out in the social media as well and you can add the comments also i will try to reach you out as soon as possible now with that done let's go to the terminal let's see cube ctl get all this will define this will give you the list of all the resources or all the components that you have created you can see that there is only a default kubernetes service available and if you see cube ctl get notes you will get the different nodes available we have one node available that is our mini cube let me clear this out and if you see cube ctl cluster info you will get the information of your cluster so this all commands you should be familiar with when you are working with the kubernetes and if you see mini cube service list over here sorry you will get the list of services available okay you can see that these are the services available these are all the default services available let's clear this out we'll go to the f drive cd okay it is okay this is the folder where all our files we have created okay this is the folder it is we created all our files over here now if you see over here cube ctl get all nothing is there now with this one command we will deploy everything we will just use cube ctl apply means apply all the configuration that we have hyphen f with the file and with all the files inside this particular folder so once we hit enter you can see that everything is created right deployment app created service created cloud config server created all these particular things are created and if you come here again and if you do get all you can see that every information over here that this many pods are created this many services are created this many deployments are created and this many replica set is created and this is the stateful site it's been created you can see the status of everything these are been getting ready these are container creating and here you can see that everything will be ready within some time and if you want any information what's happening what you can do is you can get cube cpl describe and you can give the particular name of the resource and you can see that what's happening where you will get all the information about it okay what's happening is you can see that it pulls the image successfully pull the image created the container started the container for all the ip address where it is connected with services is connected all those information you can get from the cube ctl describe command let's clear it out let's get again that all and you can see that config server is created cloud gateway is created department service is created uric server is still not created histic dashboard is still not created user service is created right and here also you can see that everything is created deployment district dashboard is still not yet done okay stateful site is also not done yet and if you see the services over here all those service you can see that are having cluster ip okay for all this cluster ip you can see that there is no external ip and for the load balancer you can see that it's still panning it's not external life is not created yet but that's fine and for the eureka over here you can see that this cluster ip this is the headless service that we have created for that you can see cluster ip is none so we'll wait for some time to complete this entire process once every application is ready and here you can see that everything is ready over here okay so we'll use the different commands to get all the information we'll use cube ctl get parts to get the pods over here so these are the parts we'll use cube ctl get svc to get the services available we use cuba ctl get deployments to get the deployments over here or you can use cubectl get all to get all the resources available now if you see the mini cube service list okay you will see all the different services now whichever we created over here yeah you can see that you see all those different services available right whatever we created you can see that no node port available that means this particular are cluster ips okay and for the others we can see that the port is available so we can connect externally now as we have deployed everything in our mini cube in our local machine we need to do the port forwarding so we can connect from our local application host application to our kubernetes cluster so we'll use the port forward command that is cube ctl tube ctl port forward command and where you have to define for which particular you have to do the port forwarding port forwarding suppose i want port forwarding for this particular user service i can do that and then after that i need to define what will be the host port and to which particular port i need to connect to so that's the command over here i found this very good application that allows you to do the same thing from the application okay so if you go to this one cube forwarder over here from pixel point this is a really good application where you can use this application to do the port forwarding in your local environment or for any of the kubernetes cluster ideally in the production environment you won't be doing this port forwarding you will be accessing everything using your load balancer or your ingress service so let's just use this particular application so you will get a hang of it how this particular thing has been used so you can download from here i will add this link in the description below you can check this out as well so i've just installed over here okay yeah if you open this you will be getting this information you can add the cluster over here i have a mini cube cluster already so it will be added and yeah you can add the resources over here so yeah here i'll add the resource from the mini cube cluster the namespace is default okay i have deployed everything in the default namespace you can define the uh your own namespace and you can deploy everything in that particular namespace as well i'll select the kind as a service i want to expose the service i want to expose the eureka load balancer service and here i need to define the local port i'm defining 8761 and the resource port is 18 because my service is running on port 80 if you add the resource it will be added over here and you can start the port forwarding over here and once you click over here you will be able to redirect and here you can see that you are able to redirect to this particular eureka server and if you see this eureka server is running in our kubernetes cluster and you can see that it is able to attach all the services available right api gateway config server department service history dashboard user service all these particular things are available now now what we will be doing is now currently you can see that we are just able to connect to this particular euro card load balancer that is the eureka ib service that we have added the port forwarding we want to do the port forwarding for the api gateway as well for now in our local so that we can access our application so let's add one resources over here default namespace we'll do the service we'll do the cloud gateway service and this cloud gateway service is running on which port we need to see that if you go over here service cloud gateway service is running on port 80 and i want that particular service to running on port 9191 as we intended in our application okay if you see here it's running on port 9191 right so we'll do the same way over here my local port is 9191 and my resource port is 80. add to the cluster start the port forwarding and i will be able to access this now let's go to the postman and let's access this now still you can see that if you go to our cluster information you can see that my department service user service are internal service or cluster ibs so that they are not exposed directly only the api server is exposed so we'll be accessing using the api server so here what we'll be doing is we'll just use the department and we'll use the post mapping over here in the body we need to give the let's just save this information for now okay we need to give the department information so let's see what data that we need to give in the department service okay we need to get the department id so we'll give the department id department name department address and the department code will remove this information will give department id1 department has id addresses so bangalore and department code as i just say it 0 6. here you can see that i'm accessing the localhost from port 9191 which i have exposed over here okay so it will go to the api gateway and internally it will call our department service to save the data so let's just hit send over here okay it's not available we need to check what happened over here so if you go to the department service over here okay it's departments okay so i just need to give departments over here and if i hit send over here it should be able to save the data okay here you can see that it's able to save the data we are getting 200 okay over here and this is the data now we have also added this service to get the data right when we pass the id over here so let's pass the id that is one and we'll use the get method because it's a get mapping over here to get the data if you hit send over here you can see that we are getting the save data over here now let's use the user service as well we'll use the user service to save the user over here we'll use the post mapping we'll give this same information over here and we'll hit send and here you can see that we are able to save this particular user as well this particular user service is calling the department series when we get the data suppose i want this particular user's data over here if i hit send over here you can see that we are getting the user data along with its department data and here this particular department has been called from the service registry if you check out the code over here okay in the user service to get the user with department what we are doing is we are calling the we are getting the department from the service registry we are calling the service to this to url that is department service and we are getting the data so from the user service we are calling the department service to get the data so you can see that everything is working smoothly over here right now one thing to note over here is as you can see that we have deployed everything as a single replica right everything is within the one replica over here now suppose we have a necessity or we have a requirement to scale up our application and suppose we want to scale up our user service okay so we can scale this up as well and i have kept this particular user service you can see that this particular user service and department service both uses in memory as to database so if we replicate all those things for now we can identify that this particular request are going to the different nodes according to the request that we make so in the one service we have added the data but when we replicate it when we scale up in the other service we won't be getting the data so when we call this particular service sometimes we might get the data and sometimes we might not get the data from that particular thing we can identify that internal load balancing is working fine so let me just scale up the department service over here or let's kill the user service as we are as we are getting the user data over here currently if you see over here let me clear this out and if you see over here you can see there is only single part available for our department service and i already told you earlier the difference between deployment and state full set if you see the difference when the pod is created using the deployment you can see that the random name is generated and appended at the end but when you create using the stateful set you will be created using the name of the stateful set that you have added with the replication index over here so with that particular thing pod name that is eureka zero service name that is dot eureka we are able to call this need right now let's scale up our department service so what we'll be doing is so we'll be just doing cube ctl scale replica equals to three suppose okay so i just want to scale this particular one of the deployments here hyphen f i will provide let me just go to that particular folder first right and here i can say cube ctl scale replica equals to 3 3 and then with hyphen f i need to pass user service so in this particular user service.dml file there are two components available that is a deployment and the other one is the service so we might get the error for the service but we will be able to scale up the deployment over here so let's run this and here you can see that we are getting the error because replica is unknown sorry it should be replicas okay and here you can see that deployment.app okay that has been scaled and there is an error for the service so that's fine let me just clear this out let's do cube ctl get all and here you can see that there are three parts available for this particular user service okay and if you go to the deployments you can see that there are three deployments three pods running and three are available now and now if we go to the postman over here and if we try to hit the user service we might get data sometimes we might not get data sometimes based upon the request which has been traversed to the pods so yeah we are getting the data sometimes you might not get the data right there is some error over here yeah you can see that sometimes we are getting the data so just ignoring the error for now but this is how the load balancing will work internally when you scale up the application okay and here also you can see that we are getting the replicas over here now this kubernetes comes with the kubernetes dashboard over here so let's open that particular dashboard also and see how it is okay and yeah if we see mini cube dashboard over here this particular kubernetes dashboard will start okay so let's see that as well in the ui form whatever we are seeing over here in the command line and here you can see that this is my kubernetes dashboard you can see that my deployments pods replica set stateful set everything is healthy over here yeah you can see the list of everything this many deployments are there how many pods are available how many pods are there the replica sets stateful sets discovery load balancing everything is working correctly right and here you can see that there's something going on with the cloud gateway that might be the reason that we got error when we hit the user service okay so you will get all those information over here accordingly this is all you can traverse through the entire application over here if you go back to our terminal we'll do cpl get all this is all the components available now with the one command we can delete the entire kubernetes cluster as well before that if you want to enable few more of the things available suppose if you want to get the particular historic dashboard right history dashboard is a node port so we can access historic dashboard over here so if you want we can start as well we have to do the port forwarding i'll add the service i'll add the rest dashboard service historic dashboard service should be working on which port we have do you find it's on port 9295 right so we can define the same port over here 9295 and the resource port is 88 because our service is running on port 80. let's add the resource let's do the port forwarding and if you go over here and if you do tricks you can see that your history dashboard is working so everything is working right so this is how you can configure everything and you can see that every entire application we started using a single command over here we did a lot of processing earlier to create the docker images and everything but everything can be automated using the ci cd pipeline either with circle ci or jenkins or git csd anything or get up actions also so these are the things that you can do for the kubernetes cluster to work let's delete the entire kubernetes cluster with the command rather than applying what we did we can do cube ctl delete hyphen f dot slash so it will delete the all the components available in the kubernetes cluster so if you see everything is deleted if you see again open the scatter you can see that everything is getting terminated so within few seconds everything will be terminated now there are a lot of things that we can do to improve our kubernetes configuration like we can add the health checks in our kubernetes cluster we can add the liveness probe and readiness pro i have created a dedicated video on that you can check that video as well you can do the graceful shutdown also with this there are a lot of things that you can add you can add the resource configurations for this kubernetes cluster how much resources of the nodes or of the virtual machines can be allocated to the any of the resource that all configurations also we can do within the kubernetes cluster we can create a different name space according to the different components we have like front-end components back-end components these are the namespace that we can create and we can create a different namespace based on the different environment or based on the different team as well these are all the things that we can do within the kubernetes cluster it's very easy just a configuration you will get all those details from the kubernetes docs as well i have created the video as well for all the different components you can check that out as well and if you see get all you can see that everything is deleted only when default kubernetes ip services there and if you try to access everything again nothing will be accessible now and here in the kubernetes dashboard you can see that nothing is available right only mini cube cluster information is there you can see everything is deleted so that's how you can deploy all the components all your micro services within the kubernetes cluster so that's all i have to share in this video i know it's a long video but if you have any doubts whatever we did over here let me know in the comment section below i will try to reach you out as soon as possible i hope you like this video so give us a thumbs up it will motivate me a lot to create more such videos like this and subscribe to my channel as well so that's all i will see you in the next video till then happy recording bye [Music]
Info
Channel: Daily Code Buffer
Views: 38,669
Rating: undefined out of 5
Keywords: kubernetes deployment tutorial, kubernetes deployment example, kubernetes, microservices, deploying spring boot in kubernetes, deployment in kubernetes, kubernetes deployment, spring boot in kubernetes, Deploying Springboot Microservices to Kubernetes Cluster, deploy microservices to kubernetes, microservices deployment using docker and kubernetes, spring boot microservices, spring boot kubernetes tutorial, microservices deployment using kubernetes, kubernetes tutorial
Id: VAmntTPebKE
Channel Id: undefined
Length: 62min 43sec (3763 seconds)
Published: Fri Apr 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.