Kubernetes YML Generator with Usage for Deployment and Service | K8s Primer | Tech Primers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the last video we saw how to deploy a spring boot application inside the kubernetes cluster however if you notice we had done that using some command-line arguments we did not leverage the complete flexibility of the platform so we wanted to create a Yaman file in order to deploy our applications deployments so create services and then upgrade applications in this video we will see how we can use a Yaman file to deploy an application both in terms of creating deployment objects and creating service objects also we are going to use a tool which will create our gamal automatically let's get started [Music] there's the bell icon on the YouTube app and never miss any a pig from egg framers so if you had seen the last video this is the github page which I had created with all the commands which we ran and some part of the video so you can use it and write out in your google cloud account so I'll be using the kubernetes engine inside google cloud platform the same way I destroyed my cluster after I showed the demo and now I'm going to rebuild the cluster so that way I'm not charged for my compute which I created so I'll give the same name which I gave in the last video right tech prime was cluster 1 I'll create 3 node cluster and hit the create option this will in the background create 3 different nodes in a kubernetes cluster and it is going to give that specifically for our account meanwhile if you look at the architecture what we did we uploaded the docker image after creating the docker image out of that Springwood application into a container registry so some of you had requested me to make that particular registry public so I will do that now so that you can pull the image and then do try out what I am doing now let me go to the container registry images here I can see the visibility let me do a low settings I'll make it public so I have made my repository public so you can go and take my images these to our example images have been trying out different samples to deploy into different clusters or some other examples so I have made the image public so you can use the same image which I am gonna show in this particular video parallely while the cluster is getting created I am going to open the cloud shell so cloud shell is a terminal which I am gonna use in order to perform my cube CTL commands inside the cluster so I'm not gonna install g-cloud in my local machine and then have the cube CTL installed in my local machine I'm going to use the cloud shell which gives me a temporary space so if you are not aware above clouds will cloud shell is temporary space provided by Google cloud platform so that you can perform some compute on your login so this is where our projects are so these are the different examples which you would have seen so the spring boot lazy init example is what we saw so let's go into this same project if you have not seen the previous video I would suggest go and take a look at it because this particular video is based on the context of what we did in the previous video so I will put the link for that particular video in the right top corner or you can take a look at it from the description below so let's do a clear if I do LS NRT this is the different packages so we already have the docker images built and it is already inside the container registry so I'm not going to rebuild the whole project to create a new docker image instrum reusing the same image the only difference is I'm going to create a Yaman file so I'll be showing how you can deploy objects and services inside the cluster using a Ammal file so that you can use it as a part of your continuous integration and contains delivery platform so looks like the cluster is created I got a notification so let me go there go there yeah so the my cluster is up there are three nodes in the cluster if you're not sure about the kubernetes architecture do check out my video on the kubernetes architecture now in order to deploy our application so for example here these are three different objects or instances so in kubernetes world deployments are called objects services are called objects as well so every piece of information running inside the cluster is called object so the green boxes are all deployments where our code will be running so these green boxes are different pods which could be running inside different nodes the orange one is the service object which we have created so that we can use the service object to connect to the deployment objects so one of the viewer had asked me why do we need a service there is no option for us to skip the service because in kubernetes if you want to connect to a deployment you will have to create a service so there is no other option for us to keep the service or directly connect to the deployment you have to use the service to connect to the deployments now let's go and create the yamen so I found out a tool created by Brandon Potter so he has created a Yaman generation script basically this is a UI where you enter some details and the yamen gets generated out of the box which is pretty good because most of the time the yamen file gets messed up due to space issues so this kind of Yama generation is pretty helpful when you are working with deployments and when you want to have amell's created out of the box very quickly so we are going to provide the docker image name here in order to do that we need to get the docker URL let's get the docker image URL which we have here we have to replace the dollar Google Cloud project in in my case the project ID is this fleet resolver two three seven zero one so you guys can use the same image I look what I will do is I will put the steps whatever we perform today into a new readme file or I will link it into the existing one so that you can take a look at it so I mean in fact happened us into the same on readme file so that you can try it out so this is the image so this is a URL of our image and if you notice in the right side the jump Yaman is already created like whenever we type stuff it's getting created on the fly so by default if you see it has picked up the name as ping boot application string good example the container command if you have any container specific command you can provide it for example if I you start typing it automatically adds the command section but I don't want to add anything same with the arguments if you have want to have any container specific arguments you can have that here I'm going to give the deployment name a spring good example by default it is the same name even the app label name is same so I'm not going to change anything there see that this is how you can create a Yambol from this particular UI however we want to expose some specific ports because our spring good application is running in 8080 right so I want to add this option called add port and you can have the container port running so here the port is 80 80 right so I will just add one so my port is 8080 so this will expose my deployment and make my docker instance run on the port 8080 if you notice what we had done here we gave the port 8080 as a part of the cube CTL run command now we are wrapping up all these manual stuff inside this deployment Nadya Molly so this is how you can create a yeah Mille for deployment so let's copy this and put it in our cloud shell I'll name my file as deployment Amelie I'll save it so this is going to create three different replicas basically three instance this of my application so let's do G cloud the same credential path which we need to do G cloud container cluster let's do this so that way it will log in my particular terminal into the cloud instance so it says grid credentials no cluster name okay so I think my cluster name is like primers cluster one I'll just rename it yeah so we are logged into the cluster let's give some commands I will do a clear first cube CTL get pods let's see if there are any pods running there should be nothing running right now because we don't have any application deployed yeah I've says no resource phone let's see if the service cluster IV is running cube CTL get services they should you already cluster me up the cluster IP is there so there are there are no services there are no pods running let's check if there are any deployments running cube CTL get deployment nothing is running so let's go and copy this yeah Mel so we copied already I think right so we copied the deploy the Amal in this particular folder but you can have it outside the target folder right now I think I'm in the target folder so I pasted it there that should be okay in order to deploy this particular yeah Mel in order to create a deployment object using this particular URL you need to give the command cube CTL apply - and the part of the amel file so in our case it's called a pomander yeah milled so previously we used to run cubes ETL run spring boot and then we provided an image and then we provided a port now we don't have to do that you can do a cube CTL create and provide a diploid or Yaman and then you can do a ply or you can by default use the apply so apply will do either create or update create will do only create so let's hit the enter option and see if the deployment is getting created so kubernetes now says that spring good example got created now in order to check it will do cube CTL get deployment this should show us all the running deployments so we have three instances of Springwood example running let's look at cube CTL get pods this should show all the three pods which are running in the cluster so we have the three plots so now if we can do cube CTL get services there should be no services running right yeah there is only cluster IP which is running now how do we connect to this particular instance or how do we connect to these instances there are three right so we need to connect to these instances to get the response back or hit that particular rest endpoint which we have exposed from that service or the deployment how to do it we need to create a service in order to do the service last time what we did we did a expose deployment and then we created a little load balancer service however now we need to create something called as a service object so let's try doing it so in the Amal crater created by Brandon there is this option called expose service port the moment you click on expose service port notice that a new section pops up in the same llaman there is one good thing about Yambol you can have multiple applications into the same Yama so that way this particular part of the amyl corresponds to a different object and the second part corresponds to a different object the way cuban it is parses this gamal file it knows that this is a separate object and this is a separate object so in our case we are going to create two different files but you can also create a single file with - - as the separation point and you can use for deploying deployments and services together so here what it is it saying so it's automatically adding something called as a service and it gave the name of this particular service a spring good example service labels also a singing good example service also notice that it created something called as a selector and the app and that is how the service identifies what are the names of the pods which are running so if you look at it there is an option called as the app label here the moment I change the app label to for example demo automatically if you seen in the right side this particular option got changed to demo on this particular option got changed to demo basically this is how a tag works so if you had remembered what I had mentioned in the architecture diagram if you go back to the older one see this is the one right so we had something called as tags and using the tags the app 1 is identified by these servers here so this is the deployment this is a service and the service connects to the deployment using the tag and that's what we are doing here so our tired name is called demo in this case we can you can provide any tag name I'm just going to remove it by default it's gonna add my application name as the tag name so let it use the same right and you can override the service name by providing the service name here I'm not going to use the - service one so I'm going to use the same name Springwood example and notice that there is something called as service type so what kind of service we are going to create already there is a cluster IP running right so in the cluster I don't want to create it so see that there's already a cluster IP running I don't want to create it let's create a load balancer because load balancer is the one which will create abstraction over our deployment so whatever the plumbs we deployed these three deployments we need to have an abstraction so that when we connect to this particular service it it automatically routes our request to whichever service is free so that's what we are doing here let's come back let me come back to the yamen yep so we are done so this is how a service definition so if you see the ports exposure 80 to 80 D but we need 8080 right so let me go and change it because my Springwood application is running in 8080 right and in order to see the hogs inside a cluster or a pod you can just do cube CTL get sorry logs and give the pod name so the pod name is here right when we did a get pods we got the pod name so let me copy it and paste it so cube CTL logs and then the pod name this will give me the log name so notice that this guy is saying that it is trying to pull the image but it is not so let me do a cube so looks like there is a problem while pulling the image right so because the log says error from the ever from a server contain a spring good application in part is trying and failing to pull the theme pull the image so let's see what happened in the deployment dot Yaman let's open that file so what's happening it said GCR taught io / fleet resolver slash spring boot example - v1 so this is exactly the same name we gave right so let's go to the container registry and then see what is happening let's go to images so let me go here I'll just copy this right and let me paste it so this is exactly the same right - 3 7 0 1 6 so let's check this in D 2 3 7 0 okay there is a typo there so we have put two three seven zero one okay so this is how you can debug your logs from the cluster so unfortunately I gave the wrong cloud ID I didn't do it intentionally but unfortunately that's what happened so let's try reapplying and then see if it works right because now we know that we did a mistake and if you notice cobalt is now says as it is saying configured instead of saying created it says configured let's now try doing the get pods and let's see if the status is good yep look the look at that older one right so there is a pod which is getting terminated and the others are getting created on the fly so we we can just do again we should see only three running parts yeah they're good now if I do a cube CTL logs and then if I give the pods name see that the board names are all dynamic right so the old pod names are different these are the old pod names the new board names are completely different so that's why you need to create a service in order to connect to these spots see these are this is the log statement and let's look for the port number yeah the port number is 8080 that's why we came here right so the port number is 8080 and we're good so this is the service definition so we have created the load balancer llaman for the service and let's create the service right now there is no service red cube CTL get services should show only the cluster IP and not the load balancer let's create that I'll create the VI service dot Yaman so this is my service definition so let me close it oh I think I gave the wrong name I should have you on Dottie Amla yep so this is what we are doing here so we are saying link spring good example with the service which you are creating as a load balancer same way you can do the cube CTL apply - f and say service dot Yamla so let's see what happens let's - oops get services this should create a new service so we have a service created it's called spring good example and it's of type load balancer and there is a cluster IEP there is an external IP which is pending right now once the external IP is provided to us we will be using the external IP and hitting our endpoints right in case of so someone was asking me why do we need an external IP how do I make it load balance right you can use a DNS to create it I will not show that DNS part in this particular video but we'll see I need to explore in the GCP how can I create a DNS I have tried the DNS part before but it works outside the GCP platform but I want to try it out in the GCP platform before showing it as a demo so I'll try that in the next video so for this video let's have our agenda simple on how to create the yamen and use the yamen to create our deployment objects look at the latest response we have the external IP let's use it and then say 8080 this should hit our deployments see that it's directly hitting there's a respond point called lazy and it is a returning hello YouTube so it works right so let me refresh it yep it goes to different different instances now it's all like not going down right so that's what is happening let me go back to my I can just do a cube CTL get pods to show you get deployments basically so I can do a cube sweetie little gap to implement and see how many instances of my deployments are running see there are three and three are available if one goes down it will show up here and the controller in the Kuban it is cluster will try to create a new pod whenever it requires it now how do we apply new changes right so in order to apply new change you can do the same cube CTL apply in order to do that let's try creating our new image alright that's what we wanted we don't want to reuse the existing image instead what I will do is I'll go to my source code and I want to change the hello YouTube - hello tech primers right I don't want to see that same message but now I want to use new message so that I can show you guys how my changes are applied in the cluster so let's change this to take primers let me go back I'll do a maven even clean install so this is going to clear my target folder so actually our deployed or diploma not you Yama land the cells not yeah Mel's we're in the target but that's fine we can use it from here right because we are using the same I can in fact show you how we can update it together so let me copy it and I will in fact paste it in the root so that we can use it so the build is happening let's wait for the bill to complete and we will create a cubed or tamil writer which has board deployment and service together in the same Yama definition and we will use it so the build is successful let's create the qbr mold here and then keep it before we lose it and just keep it here that's it now how do we build the image right in the last video you would have seen now I showed a example of how you can run image using the jib maven plug-in created by Google so I'm going to use the same but in this case I'm going to create a new version called v2 right because we need to deploy a new version of the image because we have a new version of the product so I'll do the same I will do a maven build with that particular plug-in and I'm going to upload to my registry with a new version so let's go and check in the registry once this gets uploaded I'll go and check if it is good right so let me go to the container registry right now if you see here there is only one version if i refresh i should see the second version if it has got uploaded let's check if it is okay now it's pushing the image you know it's getting built let it push and then I'll go back and see once the images are pushed so the image is pushed now let me go back and refresh I should see a new version so you guys can use the same right so if you want to use the version to use v2 if you want to use the version one use v1 now I need to modify my QB Ammal right so let me go to QB amel and I need to change my v1 to v2 so I have done that I have changed maybe you want to v2 let me save it you know to apply my changes into the cluster I can use the same cube CTL apply a hyphen F and then in this case I'm using QB Ammal if you're creating new instances you can do a create but if you want to generally update stuff then you can do an update apply so see here deployment got configured and the server's got changed that's what it says cube CTL you get pods cube CTL get deployment and see that the age is 21 seconds so which is now all right so it just happened now cube CTO get so this should show me the services yeah see that this is got deployed but nothing would have changed because the service did not change right so that's what it said here all right the service did not change it says unchanged because we did not change anything with the service definition however we change something with the image right so the service is undisrupted now if I hit the same lazy endpoint this should return me take primers right yeah it returned thickness so that's how you can do a upgrade but the only downside is we did not deploy any strategy right as a part of this particular upgrade we just did a plain deployment we did not apply any type of strategy for example Bluegreen deployment or rolling updates we can take a look at that if you guys are interested in the next video I will show you how you can do rolling update inside kubernetes how it deploys one by one in each of these replicas basically we had three replicas right it deploys one by one and then we can see how how kubernetes is intelligent enough to do that automatically right so if you guys are interested let me know in the comment section below I will go ahead and do a video on that in the next video on kubernetes so I'll just summarize what we did as a part of this particular video we first initially created a cluster and we try to create different deployment objects using a Yama file and we did it using cube CTL apply command and we also created a service using the same command but with a different DML definition which we created out of the yamen creator which we have here once we created we wanted to deploy a new code into the deployment so what we did is we rebuilt our image by modifying some changes in the source code and then we rebuilt and then uploaded it into the Google container registry and we updated the ml file using the same cube apply command and only the deployments got changed and the service did not get changed because there was no change in the amal definition so this is how you can use communities to deploy applications into kubernetes and upgrade your application whenever you require so the good part about kubernetes is most of the steps you perform are all based on command-line interfaces so whatever I showed you we perform lots of different commands right I'll use these come and then I'll add that into the readme so that you can take a look at it everything is mused on command so you can automatically add these into your continuous integration and continuous deployment pipelines so that you can automate your deployment into end I hope you got something out of this particular video do try out commanders deployments in a Google cloud platform which is completely free I am using the same let me know what do you feel what are the issues you guys are facing as always if you like the video go ahead and like it if you haven't subscribed to the channel go ahead and subscribe to it meet you again in the next video thank you very much [Music]
Info
Channel: Tech Primers
Views: 11,100
Rating: undefined out of 5
Keywords: techprimers, tech primers, service and deployment in kubernetes, kubernetes deployment, kubernetes yml generator, kubernetes yml builder, how to deploy to kubernetes, deployment and service in kubernetes, how to deploy to k8s, commands to deploy to k8s, view logs in k8s, deploying kubernetes, spring boot with kubernetes, spring boot in docker, kubernetes objects deployment and service
Id: ZHY8Zd4R874
Channel Id: undefined
Length: 26min 26sec (1586 seconds)
Published: Sat May 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.