Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What will happen to evicted pods in kubernetes?

Tags:

kubernetes

I just saw some of my pods got evicted by kubernetes. What will happen to them? just hanging around like that or I have to delete them manually?

like image 250
reachlin Avatar asked Sep 26 '17 06:09

reachlin


People also ask

What happens when POD is evicted?

Pods are evicted according to the resource, like memory or disk space, causing the node pressure. The first pods to be evicted are those in a failed state, since they are not running but could still be using resources. After this, Kubernetes evaluates the running pods.

What does evicted pod mean?

Eviction is the process of proactively terminating one or more Pods on resource-starved Nodes. 1: Kubernetes Scheduler. 2: Assigning Pods to Nodes. 3: Pod Overhead.

What is the reason for pods evicted in Kubernetes?

So Kubernetes will evict a certain number of pods from the node to ensure that there are enough resources on the node. When incompressible resources run low, Kubernetes use kubelets to evict pods. Each compute node's kubelet monitors the node's resource usage by capturing cAdvisor metrics.

How do you resolve an eviction pod in Kubernetes?

Delete Evicted Pods We can use the kubectl delete pod command to delete any pod in Kuberenetes. But with this command, we need to provide the pod name to delete any particular pod. The above command will delete the pod with name nginx-07rdsz in studytonight namespace and will release all the resources held by that pod.


3 Answers

A quick workaround I use, is to delete all evicted pods manually after an incident. You can use this command:

kubectl get pods --all-namespaces -o json | jq '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | "kubectl delete pods \(.metadata.name) -n \(.metadata.namespace)"' | xargs -n 1 bash -c
like image 186
Kalvin Avatar answered Oct 17 '22 00:10

Kalvin


To delete pods in Failed state in namespace default

kubectl -n default delete pods --field-selector=status.phase=Failed
like image 105
ticapix Avatar answered Oct 17 '22 01:10

ticapix


Evicted pods should be manually deleted. You can use following command to delete all pods in Error state.

kubectl get pods --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -
like image 35
Hansika Weerasena Avatar answered Oct 17 '22 01:10

Hansika Weerasena