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

--

--

--

DevOps | SRE | #GDE

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

10X Engineer Series Part 1: What Is It?

The day iOS replaces macOS is closer than you think

Load Document From Azure Blob Storage and View in .NET Core Application

“Kubeforming”: going full declarative with Kubernetes and AWS

Bind a custom SSL Certificate to an Azure Web App

Multiple git configs (profiles) on one computer

Prototyping native apps with React Native and Expo.io

AWS EKS (Elastic Kubernetes Service ) to deploy Jenkins

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
Raju Dawadi

Raju Dawadi

DevOps | SRE | #GDE

More from Medium

Key Metrics to Monitor in Starter Kubernetes Setup

Kubernetes Analogy Series: Authentication vs Authorization vs Admission Controller

Monitor ArgoCD applications using Prometheus and AlertManager

Environment based Kubernetes manifests with Kustomize