Kubectl Basic Commands - Create and Debug Pod in a Minikube cluster | Kubernetes Tutorial 18

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video I'm gonna show you some basic cube CTO comments and how to create and debug pots in mini cube [Music] so now we have a mini cube cluster and cube CTL installed and once the cluster is set up you're gonna be using cube CTL to basically do anything in the cluster to create components to get the status etc so first thing we are gonna just get the status of the nodes so we see that there is one node which is a master and everything's gonna run on that note because it's a mini cube so it keeps it he'll get I can check the plots and I don't have any that's why no resources I can check the services keep still get services and I just have one default service and so on so this keeps the tailgate I can list any criminal's components so now since we don't have any pots we're gonna create one and to create kubernetes components there is a cube CTL create comment so if I do help on that cube Setia create command I can see available commands for it so I can create all these components using cube city I'll create but there is no pod on the list because in kubernetes world the way it works is that the pod is the smallest unit of the kubernetes cluster but usually in practice you're not creating pots or you're not working with the pots directly there is an abstraction layer over the pots that is called deployment so this is what we are going to be creating and that's gonna create the pots underneath and this is a usage of cube CTL create deployment so I need to give a name of the deployment and then provide some options and the option that is required is the image because the pod needs to be created based on certain some image or some container image so let's actually go ahead and create nginx deployment so cube CTL create deployment we let's call it nginx deployment image equals and she's just gonna go ahead and download the latest nginx image from docker hub that's how it's gonna work so when I execute this you see deployment nginx people created so now if I do keep CTL get deployment you see that I have one deployment created I have a status here which says it's not ready yet so if I do cube City I'll get pod you see that now I have a pod which has a prefix of the deployment in some random hash here and it says container creating so it's not ready yet so if I do it again it's running and the way it works here is that when I create a deployment deployment has all the information or the blueprint for creating the pod the further this is the minimalistic or the most basic configuration for a deployment we're just saying the name and the image that's it the rest is just defaults and between deployment and apart there is another layer which is automatically managed by kubernetes deployment called replica set so if I do cube city I'll get replica set written together you see I have an engine X tipple replica set hash and it just gives me a state and if you notice here the pod name has a prefix of deployment and the replica sets ID and then its own ID so this is how the pod name is made up and the replica set basically is managing the replicas of a pod you in practice will never have to create replica set or delete a replica set or update in any way you're gonna be working with deployments directly which is more convenient because in deployment you can configure the pod blueprint completely you can say how many replicas of the you want and you can do the rest of the configuration there here with this command we just created one pot or one replica but if you wanted to have two replicas of the nginx part we can just provide as additional options so this is how the layers work first you have the deployment the deployment manages a replica set a replica set manages all the replicas of that pot and the part is again an abstraction of a container and everything below the deployment should be managed automatically by kubernetes usually have to worry about any of it for example the image that it uses I will have to edit that in the deployment directly and not in the pot so let's go ahead and do that right away so I'm gonna do cube City edit deployment and I'm gonna provide the name Phoenix and we get an auto-generated configuration file of the deployment because in the command line we just gave two options everything else is default in order generated by kubernetes and you don't have to understand this now but I'm gonna make a separate video where I break down the configuration file and the syntax of the configuration file for now let's just go ahead and scroll to the image which is somewhere down below and let's say I wanted to fixate the version to 116 and save that change and SEC deployment was edited and now when I do cube city I'll get hot I see that the old pod so this one here is terminating and another one started 25 seconds ago so if I do it again the old part is gone and the new one got created with a new image and if I do if I get replica set I see that the old one has no pots in it and a new one has been created as well so we just edited the deployment configuration and everything else below that God automatically updated and that's the magic of kubernetes and that's how it works another very practical command is keep city locks which basically shows you what the application running inside the pod actually locked so if I do keeps it here logs and I will need the pod name for this I will get nothing because nginx didn't log anything so let's actually create another deployment from MongoDB so let's call it deployment and the image and the image will be so let's see what so now I have the MongoDB deployment creating so let's go ahead and lock that this status here means that pot was created but the container inside the pod isn't running yet and when I try to lock obviously it tells me there is no container running so it can show me and it locks so let's get the status again at this point if I'm seeing that containers and starting I can actually get some additional information by cube CTL describe pod and the pod name which here shows me what state changes happen inside the pod so it pulled the image created the container and start a container so cube city I'll get pod it should be running already so now let's log it keeps it here logs and here we see the log output so it took a little bit but this is what the MongoDB application container actually locked inside the pod and obviously if container has some problems it's gonna help with debugging to see what the application is actually printing so let's clear that and get the parts again so another very useful command when debugging when something is not working or you just want to check what's going on inside the pod is cube CTL SiC so basically what it does is that it gets a terminal of that MongoDB application container so if I do keep CTL exact interactive terminal that's what I T stands for I will need the pod name - - so so with this command I get the terminal of the MongoDB application container and as you see here I am inside the container of MongoDB as a root user so I'm in a completely different setting now and as I said this is useful in debugging or when you want to test something or try something you can enter the container look at the terminal and execute some comments inside there so we can exit that again and of course with cube CTL I can delete the pots so if I do get deployment I misspelled it so it keeps it here deployment I see that I have two of them and if I do get pod and replica said I have also two of them so let's say if I wanted to get rid of all the pods replica sets underneath I will have to delete the deployment so delete deployment and I'll have to provide the name of the deployment I'm gonna delete let's do the MongoDB delete it and now if I'm gonna say keep city I'll get pot the pot should be terminating and if I do get replica set the MongoDB replica set is gone as well and the same if I do delete deployment engine X the replica said see everything gone so all the crud operations create delete update etc happens on the deployment level and everything underneath just follows automatically in the similar way we can create other cornets resources like services etc however as you notice when we are creating grenades components like deployment using cube CTL create deployment and I misspelled it all the time you'll have to provide all these options on the command line so you'll have to say the name and you have to specify the image and then you have this option one option two etc and there could be a lot of things that you want to configure in a deployment or in a pod and obviously it will be impractical to write that all out on a command line so because of that in practice you would usually work with kubernetes configuration files meaning what component you're creating what the name of the component is what image is it based off in any other options they're all gathered in a configuration file and you just tell keep CTL to execute that configuration file and the way you do it is using cube CTL apply command and apply basically takes the file the configuration file as a parameter and does whatever you have written there so apply takes an option called - F that stands for file and here you would say the name of the file so this will be the config file dot llamo this is the format that usually going to use for configuration files and this is the command that executes whatever is in that configuration file so let's actually call the configuration file know nginx deployment and let's go ahead and create a very simplistic super basic nginx deployment file so here I'm gonna create that file so this is the basic configuration for the deployment so here I'm just specifying what I want to create I want to create a deployment the name of the deployment you can ignore these labels right now how many replicas of the pods I want to create and this plug right here that template and specification is a blueprint for the pots so specification for the deployment and specification for a pod and here we're just saying that we want one container inside of the pot with nginx image and we are gonna bind that on port 80 so this is going to be our configuration file and once we have that we can apply that configuration so deployment created somehow if I again huh I see that nginx deployment pod was created and it's running and let's also see that deployment was created 52 seconds ago and now if I wanted to change something in that deployment I can actually change my local configuration for example I wanted to replicas instead of one I can apply that again deployment nginx deployment configured and as you see the difference here is that communities can detect if the nginx deployment doesn't exist yet it's gonna create one but if it already exists and I apply the configuration file again it's gonna know that it should update it instead of creating a new one so if I do get deployment I see this is the old one or the old deployment and if I do a cube CT I'll get hot I see the old one is still there and a new one got created because I increase the replica count which means that with cube City I'll apply you can both create and update a component and obviously you can do coups ETL with services volumes any other kubernetes components just like we did it with the deployment so in the next video I'm gonna break down the syntax of the configuration file which is pretty illogical and simple actually to understand and I'm gonna explain all the different attributes and what they mean so you can write your own configuration files for different components so to summarize we've looked at a couple of coops ETL comments in this video we saw how to create a component like deployment how to edit it and delete it we saw how to get status of pods deployments replicas sets etc we also logged on the console whatever application is writing into the console in the pot and we saw how to get a terminal of a running container using cube city exact and finally we saw how to use a current configuration file to create an update components using the cube CTL apply command and last but not least we saw cube CTL described command which will when a containers and starting in a pot and you want to get some additional troubleshooting information about the pot thanks for watching the video I hope it was helpful and if it was don't forget to like it this is a video series so I will create a new one every week so if you want to be notified whenever a new video comes out then subscribe to my channel if you have any questions if something wasn't clear in the video please post them in the comment section below and I will try to answer them so thank you and see you in the next video
Info
Channel: TechWorld with Nana
Views: 50,117
Rating: 4.9658704 out of 5
Keywords: kubernetes explained, kubernetes tutorial, kubernetes tutorial for beginners, kubernetes explained simply, kubernetes basic concepts, kodekloud, kubernetes cli, kubectl commands, kubernetes in practice, kubectl tutorial, kubectl basics, kubectl basic commands, kubectl command tutorial, kubectl list pods, kubectl explained, kubectl exec, kubectl, kubectl get nodes, kubectl get deployment, kubectl get pod, kubectl apply, kubectl useful commands, techworld with nana
Id: azuwXALfyRg
Channel Id: undefined
Length: 17min 37sec (1057 seconds)
Published: Thu Feb 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.