Sunday, July 2, 2023

How to delete a Pods from a Kubernetes Node

 How to delete a Pods from a Kubernetes Node


when Managing the kubernetes cluster, you may situation to delete pods from one of your nodes.

 There are specific steps to minimise disruption of your application


First, confirm the pod located node using kubectl get nodes command.




Node should configured as unscheduled by using kubectl cordon command. This ensure that no new pods will get scheduled to the node while you are preparing it for removal or maintenance.


Now you can work on moving pods off of the node. For any pods that are controlled by a Deployment or ReplicaSet (not a StatefulSet), you can increase the replica count by the number of pods that are about to be moved off of the node and then manually delete the pods that were running on the node. If you are not concerned with having one less replica at a time, you can skip the scaling step and just delete the necessary pods one at a time.

For example, if you had a Deployment called “web” with 3 replicas, and 1 of them is running on the node that will be deleted, and it is not acceptable to only run 2 replicas at any time, you would scale the Deployment up to 4 replicas, wait for the new pod to become Ready, and then delete the old pod using kubectl delete pod.  You can then scale back down to 3 replicas to get back to your original configuration.



Once you have finished maintenance on a node, you can use the kubectl uncordon
 command to allow scheduling on the node again. Then, as pods need to be scheduled, they will appear back on that node.




No comments: