Kubectl basics for beginners | Kubernetes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what is that people and welcome to another video and in this video we'll be taking a look at a utility called cube CTL which is basically a utility to configure and operate kubernetes so in our previous video we take the we've taken a look at how to install kubernetes on docker for windows we've configured our cluster and now I want to run through the command-line utility so you can become more efficient at operating kubernetes so without further ado let's go the first thing we're going to want to do is configure cube CTL now cube CTL can point to multiple clusters so in the previous video we've gone through the process of installing kubernetes locally using docker for Windows so what that software does is it actually configures a cube config file on our behalf and that will point to the docker for Windows kubernetes cluster so we can go and configure this config file to point to any cluster so we can point to development production staging or whatever cluster you have so in this video I'm gonna show you guys how to configure a cube CTL and then some of the commands that we want to use and how to use cube CTL in general the first command that you're interested in is the cube CTL config command when you run this this will give you some more information and documentation about cube config and I will actually explain some of this quickly at a very high level now when you run any cube CTL command it looks at a cube config file now the default path is in your home directory under a dot cube folder so I have this folder already created for me under my users directory cube and there's a config file in here when you expand this config file you can see that it has multiple settings it has a list of clusters a list of users and then a list of contexts now if a cluster is just an endpoint to the way the kubernetes cluster is located and then a user has the credentials with any k to that cluster and then what a context is as a context is basically a configuration that points you to the cluster so we're interested in the context so we're gonna have like a local docker for desktop context that is the kubernetes cluster that runs locally and then we can have like a production context or a dev or staging context now that's the simplest way is to have a config file in your users folder you can also if you have a multiple configs you can pass them in by saying cube CTL config and then just passing the cube config flag to some other conflict path that's also one way of doing it another way of doing it is setting an environment variable called cube config and you can actually have like multiple paths separated by : and when cube CTL runs it'll look at that config first so it will basically allow you to merge configs different configuration files together so when working with kubernetes configs the main thing we're interested in is the contexts because that tells us which cluster we're pointing at so you want to run this command cube CTL config current context and that'll tell you the cluster you're pointing at and what you can also do is a basically the set the gates and set commands so the this one here if you copy that and run that that'll get to the current context it'll give you all the contexts that you have in your config and it'll have a little star next to the one that is currently set and then you can also change the context by using this command to say use context and then you can just type in the name of a different context here and that allows you to switch between different kubernetes clusters the next important command is the gate come on this allows you to retrieve kubernetes resources now in future videos I'm actually gonna deep dive into every type of kubernetes object and basically explain what it means and how to create them and but in this video I want to just show you guys how to run the get come on so you can say keep CTL get pods and that'll list pods very simple you can do keep CT I'll get deployments that'll list any deployments you can say cube CT I'll get services that'll list out the services we have one service running there you can do config Maps you can do secrets there's a default secret in that cluster and in Greece so that's how you just retrieve resources the next type of kubernetes object that's quite important to work with is namespaces now normally resources are scoped to a namespace and in namespaces like a project group or like a resource group or like a just a group of objects now in kubernetes namespaces can be used to isolate resources so you can have a namespace per team my namespace per business unit name space per department or however you wanted to set it up it allows you to separate resources from one another now when we do that get command we can also pass in a name space to get the pods that are associated with that namespace or any resource associated with it so in order to create or to get namespaces we use the git command so we say get namespaces we can see we have a bunch of namespaces here and we can create our own one call test so we say cube CT I'll create namespace test and that namespace is created I can go and run the get one again and see it's been created five seconds ago now it's important to notice that there is a default namespace in the cluster and when you run these git commands or any command in that matter that applies to a namespace it'll always use the default namespace so if you say get pods cuba Nettie's will look at the default namespace and see there are no pods in there if we want to get the pots for a specific namespace we have to pass it in using the dash in flag and we can just pass in a name of our namespace and that'll get the pods associate with that namespace the next command I want to show you guys is called the describe command this one is very important other than the git command because the gate come on will listen to you some pods it'll show you a status so if you say keep CT I'll get pods you'll see a list of pods with the statuses if you say git nodes you'll get the machines with this data says etc but sometimes you need to look need a little bit more than that like you need the events and some sort of states that that object is in and maybe some past historical events so for that we use the cube CTL describe command now because we don't have anything in this kubernetes cluster yet what I want to do is show you guys if you say cube CT I'll get an S which is namespaces that's the short abbreviated term it'll list out the namespaces so I'm gonna use the cube system namespace and I'm just gonna list out all the pods so I'm gonna say cube CT I'll get pods for the namespace cube system and then we'll list out all the pods in that namespace and I'm just gonna grab a random pod here and I'm gonna say cube CTL describe pod and then the name of the pod and then also again the name of the namespace you remember otherwise it'll go look in the default so I do that and now you can see a lot more information and this is quite useful because this tells you the namespace it's in some priority class names the node that's running on the time it was started the labels that it has it's currently running there's its IP address what else is important here the image that's running so if you want to see what version your container is your image container image if you want to see what ports are exposed arguments here's the current state so sometimes you can see when a container throws an error it'll have a state here saying like exit code that's very important or if it's running out of memory it'll have a oom killed or any kind of exceptions it's throwing if it's crashing there'll be a crash Lubeck if it has any limits and requests values for resources probes mounts this is important some of the conditions and then there are also events now normally when there's some sort of crash data is happening or some problem you will see events here that'll tell you what's wrong with that resource so this is a very good command describe and I normally use it for like to describe deployments to describe pods and to describe nodes so if the underlying infrastructure is problematic like a virtual machine I say cube CT I'll describe node and the name of the node or if there's a container that's hanging up I just say cube CT I'll describe pod and then the name of the pod and the final command that we gonna be running through in this video is the version so this is important when you're working with clusters have multiple versions you type keep CTL version and that'll tell you the version of cube CT all that you have installed as well as the version of kubernetes that you're pointing to so the server version so as you can see cube CTL is quite an advanced tool and it gets a lot more advanced as we go through the process but I hope this video would help you understand the basics so in this video we cover you know how to configure cube CTL 2.2 different clusters the concept around contexts to point to different clusters and also the ability to navigate resources so to navigate the cluster and to navigate namespaces get all the different types of resource objects now in the next video we're gonna be taking taking a look at deployments so how do we deploy stuff to kubernetes and as we go along in future videos we'll be going into more advanced concepts but hopefully this video helps you get a hang of cube CTL and start using it so you can navigate your cluster and just get become an expert in the command line hope you guys enjoyed this video like and subscribe leave a comment below if there's stuff that you'd like me to cover and until next time peace [Music]
Info
Channel: That DevOps Guy
Views: 20,010
Rating: 4.9847617 out of 5
Keywords: kubernetes, kubectl, tutorial, basics, getting started, docker, windows
Id: feLpGydQVio
Channel Id: undefined
Length: 11min 3sec (663 seconds)
Published: Sat Sep 07 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.