Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all the contents from a kubernetes node

How to delete all the contents from a kubernetes node?
Contents include deployments, replica sets etc. I tried to delete deplyoments seperately. But kubernetes recreates all the pods again.
Is there there any ways to delete all the replica sets present in a node?

like image 578
Mufeed Avatar asked Jan 03 '18 13:01

Mufeed


People also ask

How do you clean Kubernetes nodes?

To remove a Kubernetes Node:Log in to the Kubernetes Node that you want to remove. Log in to the Salt Master node. Log in to any Kubernetes Master node. Wait until the workloads are gracefully deleted and the Kubernetes Node is removed.


2 Answers

If you are testing things, the easiest way would be

kubectl delete deployment --all 

Althougth if you are using minikube, the easiest would probably be delete the machine and start again with a fresh node

minikube delete minikube start 

If we are talking about a production cluster, Kubernetes has a built-in feature to drain a node of the cluster, removing all the objects from that node safely.

You can use kubectl drain to safely evict all of your pods from a node before you perform maintenance on the node. Safe evictions allow the pod’s containers to gracefully terminate and will respect the PodDisruptionBudgets you have specified.

Note: By default kubectl drain will ignore certain system pods on the node that cannot be killed; see the kubectl drain documentation for more details.

When kubectl drain returns successfully, that indicates that all of the pods (except the ones excluded as described in the previous paragraph) have been safely evicted (respecting the desired graceful termination period, and without violating any application-level disruption SLOs). It is then safe to bring down the node by powering down its physical machine or, if running on a cloud platform, deleting its virtual machine.

First, identify the name of the node you wish to drain. You can list all of the nodes in your cluster with

kubectl get nodes 

Next, tell Kubernetes to drain the node:

kubectl drain <node name> 

Once it returns (without giving an error), you can power down the node (or equivalently, if on a cloud platform, delete the virtual machine backing the node). drain waits for graceful termination. You should not operate on the machine until the command completes.

If you leave the node in the cluster during the maintenance operation, you need to run

kubectl uncordon <node name> 

afterwards to tell Kubernetes that it can resume scheduling new pods onto the node.

Please, note that if there are any pods that are not managed by ReplicationController, ReplicaSet, DaemonSet, StatefulSet or Job, then drain will not delete any pods unless you use --force, as mentioned in the docs.

kubectl drain <node name> --force 
like image 145
Jose Armesto Avatar answered Sep 24 '22 08:09

Jose Armesto


minikube delete --all  

in case you are using minikube

it will let you start a new clean cluster.


in case you run on Kubernetes :

kubectl delete pods,deployments -A --all 

it will remove it from all namespaces, you can add more objects in the same command .

like image 38
Ramzi Hosisey Avatar answered Sep 23 '22 08:09

Ramzi Hosisey