Clearing Evicted Pod in One or All Namespaces on Kubernetes Cluster

You might have seen pods in the above state on Kubernetes cluster. Eviction is the process of terminating one or multiple pods on K8s nodes which could be because of lack of resources like CPU, memory, disk space, and filesystem inodes etc. It is mostly due to resource planning difficulty and pod needs to be rescheduled from high to low pressure node.

When any of the node in the cluster is under high pressure, it starts to cleanup unused Kubernetes resources like killed container, old container images etc. If that also could not sufficiently clean server resource of the node, further containers start to get killed.

The queue of getting killed in containers list comes on top which has not well defined cpu & memory requests, limits. This should be defined on pod manifest like this:

The evicted pods can be seen with simple kubectl get pods command.

Deleting Evicted Pods In All Namespaces

To delete pods of all namespaces at once, run the following script:

Deleting Evicted Pods In Each Namespace

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store