DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Kubernetes series (Part 3): Use kubectl

Remember, kubectl contacts with apis of nodes and controls the nodes. The way it does is that, it has a config file where it keeps all of the IP address of the APIs.

  1. Firstly, we will now see our nodes using
kubectl get node
Enter fullscreen mode Exit fullscreen mode

Image description

If it responses, it means that your command line is working and you are getting back data.

You can even use

kubectl get nodes 
Enter fullscreen mode Exit fullscreen mode

or,

kubectl get no
Enter fullscreen mode Exit fullscreen mode

if you wish.

You can even get the node information in a brief or wide format with more informations

kubectl get nodes -o wide
Enter fullscreen mode Exit fullscreen mode

Image description
We can also check this information in yaml

Image description

It shows all of the information!!!!!!!!

  1. We will use describe command to see more informations about a node
kubectl describe node <node>
Enter fullscreen mode Exit fullscreen mode

Don't copy the command. First use

kubectl get node
Enter fullscreen mode Exit fullscreen mode

and copy the node name you get and then use it instead if

Image description

  1. Let's check resources we have
kubectl api-resources
Enter fullscreen mode Exit fullscreen mode

Image description

You can see the node has a kind "no"

Image description

Remember, we could use

kubectl get no
Enter fullscreen mode Exit fullscreen mode

instead of

kubectl get node
Enter fullscreen mode Exit fullscreen mode

SO, this is how this resources will help you understand short formats too.

Now , we can know much more of a particular resource using this command:

kubectl explain <type>
Enter fullscreen mode Exit fullscreen mode

instead of type, we can take "node" for an example:

Image description
if we want to check the spec, we can type

Image description

kubectl explain node.spec
Enter fullscreen mode Exit fullscreen mode

Image description

to get the list of all fields and sub-fields:

kubectl explain node --recursive
Enter fullscreen mode Exit fullscreen mode

Image description
This command basically shows in a list format.

Some resources names to be clear about:
Image description

Note: You can use kubectl api-resources and explain to see the details of resources or check from the official documentation

But , you should be able to do both

  1. Lets check out services(A service is a stable endpoint to connect to "something")
kubectl get services
Enter fullscreen mode Exit fullscreen mode

or use,

kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Image description

Lets check out the pods:

Image description

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Image description

Ahha!!!!!!! NO pods. Isn't it obvious? Have we created any containers or pods yet?

NO!!
So, how can we expect to have pods?

But, what is "default namespace" ???
Actually the commands we are using by now, use "namespace" to filter certain things. Like there are pods we did not create yet but we could not see them while using "kubectl get pods" because namespace filtered it for us.

Lets check what this namespace has got

Image description

You know what ... This kube-system thing looks suspicious.

In fact, I'm pretty sure it showed up earlier, when we did:

kubectl describe node <node-name>
Enter fullscreen mode Exit fullscreen mode

So, we have pods actually.

Lets check more ..what is inside the namespace.

kubectl get pods --all-namespaces
Enter fullscreen mode Exit fullscreen mode

or,

kubectl get pods -A
Enter fullscreen mode Exit fullscreen mode

Image description

This output is a bit different than the "kubernetes get namespace", right?
now we can see status and many more here.

You can see the coredns, node, controller etc

Image description

SO, these are basically the control plane pods . To know more about them, you can check out this image:

Image description

Note: Till now we checked out "default" namespaces. we can change it to any particular namespace. To list only the pods in the kube-system namespace

kubectl get pods --namespace=kube-system
Enter fullscreen mode Exit fullscreen mode

Image description

kubectl get pods -n kube-system
Enter fullscreen mode Exit fullscreen mode

Here, -n is used to mean namespace.

More to know:

Image description

Some other basics:
kube-public: Used for installation and then connecting to something.

Image description
Lets check what is inside of it

kubectl -n kube-public get pods
Enter fullscreen mode Exit fullscreen mode

Image description
There is nothing, right? So, what is this for? Actually this helps in configuring.It basically gives us interesting information of how to connect.

Let's check the config file:

kubectl -n kube-public get configmaps
Enter fullscreen mode Exit fullscreen mode

Image description

We can check out any of them using "file name -o yaml" adding at the end of the previous command. Here -o is to show output

Image description

So, that was it for this blog!

Top comments (0)