How to Delete All Pods in Kubernetes

A Kubernetes pod is the smallest element of a Kubernetes application, consisting of one or even more Linux containers. A pod can be made up of many, tightly interconnected containers or just a single container. Containers are organized into Kubernetes pods to improve resource allocation intelligence. A Pod represents an application-specific “logical host”: it comprises one or more tightly connected containerized applications.

Applications running on the very same physical or virtual computer in a non-cloud environment are equivalent to cloud applications running within the same logical host. When numerous containers are housed in a pod, access and data sharing between them are made easier. Because all containers in a pod have the same networking namespace, they may find and connect with one another via localhost. Pods can connect by utilizing the IP address of some other pod or by identifying a resource inside another pod.

You will almost certainly need to delete pods by one of your nodes when running your Kubernetes cluster. You may need to troubleshoot node difficulties, update the node, or even scale down your cluster. Although deleting pods from either node is not difficult, there are some measures you should follow to ensure that your application is not disrupted. We use pods to launch our applications instead of just launching containers. A pod is a pool of containers that are the part of same worker node. Each pod will have its IP address, hostname, and other processes.

In this tutorial, we are going to tell you the way to delete Kubernetes pods one by one and to delete them collectively.

Pre-requisites

To delete all pods in Kubernetes, we must check the operating system. In our case, we are using Ubuntu 20.04 operating system. However, you can check any other Linux distributions according to your requirements. Also, check that the minikube cluster is an essential component to run Kubernetes services in Linux. You need to install a minikube cluster on your system for the smooth implementation of this tutorial.

Method to Delete All Pods in Kubernetes

Now, the time comes to elaborate a method to delete all pods or a single pod in Kubernetes. Follow the appended steps to get your work done smoothly.

Step 1. Start Minikube

To start a minikube cluster, you have to open the command line terminal of your Ubuntu 20.04 sytem. You can open it by following two ways that are:

  • By searching “Terminal” in the application search area of the Ubuntu 20.04 system
  • By using the “Ctrl+Alt+T”  shortcut key

By choosing either of the above show ways, you will be able to effectively launch the terminal. Now the main purpose is to start minikube, you can do it by writing the listed command in the terminal.

$ start minikube

The whole process will take a few minutes, it is suggested to not quit the terminal until the minikube gets started. You can update the minikube cluster as well.

Step 2: Check Active Nodes

Now, we have to verify the status of nodes. For this purpose, try out the below-mentioned command along with a kubectl keyword.

$ kubectl get nodes

After the execution of the above-cited command, you can view the name, status, role, age, and version of the nodes.

Step 3: List All Pods

The most important step of this guide is to list the whole information regarding the pods present in the system. For listing purposes, you have to execute the following command on the terminal.

$ kubectl get pods

In the output of this command, you can view the names, status restarts, and ages of all pods running in your system.

Step 4: Delete Pods One by One

If you do not want to delete all pods collectively, and want to delete any specific pod, you can utilize the below-mentioned command.

$ kubectl delete pods Nginx

In our case, we have deleted the pod named “Nginx”. However, you can delete the pod as per your requirements.

Step 5: Delete All Pods

If you want to delete all pods collectively, you can do it by executing the below-listed command.

$ kubectl delete pods –all

“-all” keyword represents that all pods will be deleted.

Conclusion

In this tutorial, we have elaborated on the concept of pods and why their removal is important. Also, we have explained the method to delete the pods one by one or to delete them collectively. I hope now you can easily delete the required pods from your system conveniently.



from Linux Hint https://ift.tt/3qXsxID

Post a Comment

0 Comments