Kubernetes: useful commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
now let's look at a few useful kubernetes commands from an administrative standpoint probably the most useful command is cube CTL if you pipe that to head you can see some of the things that can do like creating resources it can also run images you can also do exec like you would do with docker and many other things first though you want to make sure that you have the path set correctly so you can do a witch cube CTL to be sure that that is the case and the default location is here or certainly a common location at least you'll use that command so often I like to create an alias so something like this where K equals cube CTL and now you can do type in K and you'll get the same output now notice that you can connect from your laptop into the kubernetes cluster and that might be running on bluemix or some other provider or possibly running privately but notice that your pc may be running Windows might be a Mac and this cluster typically is going to be running Linux but it doesn't matter because cube CTL can be run from here outside the cluster or you can run it say on the master or you can run it somewhere else say a machine somewhere else inside this cluster this part doesn't matter but what does matter is that your connection into the cluster must use a config file to do its work and of course leave it to you to make sure that the network connection here is set up but your cloud provider would give you instructions or if it's done privately you'd get instructions from an administrator now specifically cube CTL when it is running on whichever machine it is running on needs to find the configuration file in order to make this connection in and you can do that either as an environment variable on your computer or you can set it in a file if you forget and don't provide the configuration file you should expect to get an error message about a connection and this is due to the configuration file not being actively available for cube CTL let's start with the environment variable option Here I am on Windows if I do a set and do a find string so it's like a grep in CMD you can see that I have a configuration file which actually points to a yamo file now if I open that yamo file you can see the ape version the clusters it'll give you the server that you're on the certificate authority that's been set up and so on and so forth along with the provider now these are typical details for these animal files it's also important to notice the kind especially when you're looking at any mo file because it tells you what kind of file you are dealing with now because it gets annoying to type that in every single time in your show you can make sure that that is set each time you log into your shell with bash underscore profile or profile but the other way to do this is not set it in an environment variable and instead set that in a file so to make that work whichever profile you're logged into make sure that you have a dot cube directory and put the yamo file in a file called config and every time you runs cube CTL you won't need to have previously entered environment command now one of the most useful commands you can issue is cube CTL get all which will bring you a list back of all of the things running and by things I really mean resources in this case you'll see a Pio that stands for pod and in a slash and in the name of the pod that's currently running is busybox now in a more active environment you would see pods listed first then followed by services and then deployments which we haven't really covered and replica sets which we haven't covered much in detail later but notice what you're getting the cluster IP address so these all start with 10 in this case these are private IP addresses then you see the ports but these ports are not being exposed outside the cluster so these are just internal to the cluster and you'll see the age how long these have been up and running and then notice the pod names at the top you'll have the name of the pod db2 and then a unique identifier to indicate or identify a specific replica of this pod for these deployments and replica sets because we did cover slightly in an earlier video that a replica set it contains multiple replicas this tells you which replica is running on a given system now the given system isn't actually here so to find that you need to run a slightly different command which is o and then wide now you might be wondering where does the o from remember you can do a - - help that will load a go template go that's go language and you can immediately see additional information the - Oh will give you an IP address so you can see the pods IP address and you can also see the node on which that pod is currently running you also get to see the image when it comes to a deployment reference so these resources all have images so these you can sort of consider these to be the thing that is running so that runs from a particular image this is coming from a private registry that's the port 5000 here from docker and you also get the image from the replica set on which the deploy the deploy resource is based yoga you can also see the service cluster IP we saw that before we saw the ports and the only difference here is now you have a selector the selector is a label that you apply will go into this later that you apply to your deployment or your deploy resources that kind of attach themselves when you use the right ones to the service based on whatever selector so if you have an an analytics label and the selectors analytics this will get attached into that service notice to that hey get all doesn't really bring back all where all means resources what it really did under the hood was - - namespace equals its default now how would you know that well open up your configuration file and take a look there is default defined it's called the namespace and that is defined in something called the context a context lets you switch between clusters when you have multiple clusters this particular cluster is called my cluster so if you really want all then you need to issue all namespaces and you can find that if you weren't sure that it was there or how you would even get it you can do a grep for all in the help and see sure enough all namespaces and by default that is set to false its output looks like this this is interesting because now you're seeing the namespace listed in addition to the resources that are involved in case you were curious yes you can do an au wide with that which will give you a listing something like this you can also ask for just the nodes with a command like this or you can ask for just pods with something like this or if you notice it was abbreviated before as P oh and you can do the same you can also ask for a cluster information or you can ask for events things that have happened on the system you can also ask for just services you can also create resources like pods but you need to start from a llamó file here is a sample we'll be using I'm just changing the name here from busybox to my pod and then without doing anything else let's see where we're at right now so this is before creating the pod and then to create the pod you'll issue the create command and give it the - f4 file argument and then you give it the file that you want it has all the instructions and hit enter and now if we would get all we'll see we have two separate pods to delete a pod you issue the delete command and then you have to say what it is which resource that it is you want to delete and with this is a pod and then you give it the name of the pod and you'll say my pod and that will delete it which you can confirm with get all and this is interesting because you can see the progress as this moves along now if you want to see this because it may take time you can do a watch and this will show you over time how it progresses now the command will fail like it did just a second ago unless you give it the full name of the command you can't use an alias here and now you can see the progress with by default a refresh of two seconds you can also run commands on these pods with a exec just like docker would do and this is an interactive terminal and then the shell if you want the shell and in the case of busybox you now get DNS utilities which we'll be looking at soon but here's the spoiler all of the pods can communicate through to each other via DNS internal to the cluster and just like docker you're really not supposed to be opening up shells directly to these pods instead you should be running commands like this where you said just give it the command at the end of the line and that will give you the same result but notice that you do not need the IT in these cases you're not running it interactively and there's no terminal required so you really should run it like this now with Dockers exec command you need to be on that machine for the exact actually work whereas with the kubernetes exec command you'll actually run it safe from your laptop but that will connect over to the cluster as we've seen locate the node then find the pod and execute the instructions on that pod so that's very nice because he gives you a single point of administration for a vastly distributed system
Info
Channel: Sean Wingert
Views: 40,511
Rating: undefined out of 5
Keywords:
Id: K1HuOLzPSpU
Channel Id: undefined
Length: 9min 27sec (567 seconds)
Published: Fri Sep 29 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.