Kubernetes series (Part 3): Use kubectl
Tags: kubernetes
Published: 2022-07-26 13:58:52

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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4hcginr75tmb9859yw1.png)
 
If it responses, it means that your command line is working and you are getting back data.

You can even use 

```
kubectl get nodes 
```
or,

```
kubectl get no
```
if you wish.

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

```
kubectl get nodes -o wide
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9fu71csjc8uq55tau1h.png)
 We can also check this information in  yaml



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/027coipi81dkwkuy4grx.png)

It shows all of the information!!!!!!!!
 
2. We will use describe command to see more informations about a node

```
kubectl describe node <node>
```
Don't copy the command. First use 

```
kubectl get node
```
and copy the node name you get and then use it instead if <node>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im9qltf22ko7hqjs0t8v.png)


3. Let's check resources we have 

```
kubectl api-resources
```
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7dvijwyl625u44t3ohxp.png)

You can see the node has a kind "no"

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5a7206ofl8lh1s88rc6.png)

Remember, we could use 

```
kubectl get no
```

instead of 

```
kubectl get node
```

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>
```
instead of type, we can take "node" for an example:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cj2ldyee3obvplfos9by.png)
if we want to check the spec, we can type

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pj7v9p00ojo5eccnilm4.png)

  

```
kubectl explain node.spec
```
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nbaju6mpwwtc1nxb0p1g.png)
 
to get the list of all fields and sub-fields:

```
kubectl explain node --recursive
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bdnfmomhvz67mqb1a35t.png)
This command basically shows in a list format.

Some resources names to be clear about:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tvvbmidi6hpjmxubty4.png)



Note: You can use kubectl api-resources and explain to see the details of resources or check from [the official documentation](https://kubernetes.io/docs/reference/#api-reference)  

But , you should be able to do both


4. Lets check out services(A service is a stable endpoint to connect to "something")

```
kubectl get services
```
or use,

```
kubectl get svc
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pe4y17fush3taczb7r2k.png)

Lets check out the pods:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7bmro380mncug1kvfi3.png)

```
kubectl get pods
```
  

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/538sj25k0owd9ohcsrlh.png)


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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/309y1x864iywtcq77buc.png)
 

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>
```
So, we have pods actually.

Lets check more ..what is inside the namespace. 

```
kubectl get pods --all-namespaces
```
or, 

```
kubectl get pods -A
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sj1yei5wt74chm8z5p2x.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h32zkdgilzkcwjyg26eo.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lvs3oa5qrbff5c0ef7v5.png)

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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjhuz9o6b5i9nw3kym8o.png)

```
kubectl get pods -n kube-system
```
Here, -n is used to mean namespace.

More to know:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/os7njsc9nxth8m3v0v2z.png)
 
Some other basics:
kube-public: Used for installation and then connecting to something.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/to8hwpeyqo29m1fz0wvw.png)
Lets check what is inside of it

```
kubectl -n kube-public get pods
```
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/294qyuxaxu1l5x5sox6x.png) 
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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/imah54nekssjqit0z0sn.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qctlb8rxkv4y1dhojlrs.png)
 

So, that was it for this blog!
<img src="https://media0.giphy.com/media/Nfs5y1kzJKfu/giphy.gif?cid=ecf05e472d3w835ptrri5m1p6ifnwl9mi7ope9pifvhpcxf6&rid=giphy.gif&ct=g">