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

<p>If you are testing things, the easiest way would be</p>

<pre><code>kubectl delete deployment --all
</code></pre>

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

<pre><code>minikube delete
minikube start
</code></pre>

<p>If we are talking about a production cluster, <a href="https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/" rel="noreferrer">Kubernetes has a built-in feature to drain a node of the cluster</a>, removing all the objects from that node safely.</p>

<blockquote>
  <p>You can use <code>kubectl drain</code> 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.</p>
  
  <p><strong>Note</strong>: By default <code>kubectl drain</code> will ignore certain system pods on the node that cannot be killed; see the kubectl drain documentation for more details.</p>
  
  <p>When <code>kubectl drain</code> 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.</p>
</blockquote>

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

<pre><code>kubectl get nodes
</code></pre>

<p>Next, tell Kubernetes to drain the node:</p>

<pre><code>kubectl drain &lt;node name&gt;
</code></pre>

<p>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). <code>drain</code> waits for graceful termination. You should not operate on the machine until the command completes.</p>

<p>If you leave the node in the cluster during the maintenance operation, you need to run</p>

<pre><code>kubectl uncordon &lt;node name&gt;
</code></pre>

<p>afterwards to tell Kubernetes that it can resume scheduling new pods onto the node.</p>

<p>Please, note that if there are any pods that are not managed by ReplicationController, ReplicaSet, DaemonSet, StatefulSet or Job, then <code>drain</code> will not delete any pods unless you use --force, <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain" rel="noreferrer">as mentioned in the docs</a>.</p>

<pre><code>kubectl drain &lt;node name&gt; --force
</code></pre>
