Kubectl Commands
Tags: kubernetes, beginners, cloud
Published: 2021-11-12 17:47:44

In this we will be discussing about the basic Kubectl commands and how to create and debug pods in minikube.
**Minikube:** It is generally a one node cluster where the master processes and worker processes run on one node.
> To set up minikube on your local system go through this documentation [Minikube](https://minikube.sigs.k8s.io/docs/start/).

**Kubectl:** Do you remember we discussed it in our previous post [Introduction to Kubernetes](https://dev.to/bhargavkrishna/introduction-to-kubernetes-53pj).
I will make it more simpler to make you understand about kubectl.

Finally, we have virtual node on our local machine that represents minikube. Now how to interact with the cluster? How we can create pods and other Kubernetes components on the node? Any guess?
>`Kubectl`

Yes, with the help of kubectl we can interact with the cluster. Kubectl is a CLI(command-line tool) for Kubernetes cluster. To do any changes in the Kubernetes cluster first we have to talk to the API server in the master node. Here, kubectl comes into play. Kubectl helps us to talk with the API Server and it is the most power full tool to interact with the API server.

##Kubectl Commands
>`Kubectl get nodes
`To get the status of all nodes we will be using get nodes command.

>`kubectl get pods`
Displays list of all pods in the namespace.

>`kubectl get services`
Displays list of all services in the namespace.

In Kubernetes cluster we will not create pods directly there is an abstraction layer over the pods that is called deployment. We will be creating deployment and this will create pods underneath.
>`kubectl create deployment Name --image=image [--dry-run] [options]`
Example:- If we want to create nginx pod we will first create deployment of that 
`kubectl create deployment nginx-depl --image=nginx`
This will download the latest version of nginx  from the docker hub.

>`kubectl get deployment`
It lists all the deployments present.

If by any case you want to edit the deployment you can use this command.
>`kubectl edit deployment Name`
According to our example: `kubectl edit deployment nginx-depl`

**Debugging Pods**
>`kubectl logs [pod name]`
It basically shows, what the application running inside the pod actually logged. It is mainly used for debugging problems and monitoring cluster activity. Its like when you log in into any application it shows all the activity who have done till now.

If you want to get the terminal of a container we can use this command
>`kubectl exec -it [pod name] -- bin/bash`

**Delete Pods**
>`kubectl delete deployment [deployment name]`
By the help of this command we can delete the pod.

**We can deploy our applications by configuration files also.**
>`kubectl apply -f [file name]`
generally we will be having .yaml file.
>`kubectl delete -f [file name]`
we can delete the application.

These are the basic commands of kubectl but very important ones.
 
I hope you found this article useful. Reach out to me on  [Twitter](https://twitter.com/Bhargav263) to share your feedback or for any queries. I'd be more than happy to help.

Thanks for reading, See you next time.
_Sayonara._