Jay Taylor's notes
back to listing indexWhat will happen to evicted pods in kubernetes? - Stack Overflow
[web search]- Home
-
- Public
- Stack Overflow
- Tags
- Users
- Jobs
-
-
Teams
-
Free 30 Day Trial
-
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?
Evicted
state for 13 days now. Looks like evicted pods don't get removed (or maybe it is just a bug).
– Elouan Keryell-Even
Oct 23 '17 at 12:30
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
To delete pods in Failed state in namespace default
kubectl -n default delete pods --field-selector=status.phase=Failed
status.phase=Evicted
. I managed to do this by kubectl -n default delete pods --field-selector=status.phase!=Running
. But be careful, this would delete everything
– n3o
May 16 '19 at 8:29
kubectl -n default get pods --field-selector=status.phase=Failed
at first.
– username
Aug 12 '19 at 9:43
Depending on if a soft or hard eviction threshold that has been met, the Containers in the Pod will be terminated with or without grace period, the PodPhase
will be marked as Failed
and the Pod deleted. If your Application runs as part of e.g. a Deployment, there will be another Pod created and scheduled by Kubernetes - probably on another Node not exceeding its eviction thresholds.
Be aware that eviction does not necessarily have to be caused by thresholds but can also be invoked via kubectl drain
to empty a node or manually via the Kubernetes API.
kubectl describe
says "Status: Failed Reason: Evicted Message: Pod The node was low on resource: [MemoryPressure]."
– Bryan
Dec 15 '17 at 14:39
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 -
In case you have pods with a Completed
status that you want to keep around:
kubectl get pods --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -
OpenShift equivalent of Kalvin's command to delete all 'Evicted' pods:
eval "$(oc get pods --all-namespaces -o json | jq -r '.items[] | select(.status.phase == "Failed" and .status.reason == "Evicted") | "oc delete pod --namespace " + .metadata.namespace + " " + .metadata.name')"
Just in the case someone wants to automatically delete all evicted pods for all namespaces:
- Powershell
Foreach( $x in (kubectl get po --all-namespaces --field-selector=status.phase=Failed --no-headers -o custom-columns=:metadata.name)) {kubectl delete po $x --all-namespaces }
- Bash
kubectl get po --all-namespaces --field-selector=status.phase=Failed --no-headers -o custom-columns=:metadata.name | xargs kubectl delete po --all-namespaces
One more bash command to delete evicted pods
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
Kube-controller-manager
exists by default with a working K8s installation. It appears that the default is a max of 12500 terminated pods before GC kicks in.
Directly from the K8s documentation: https://kubernetes.io/docs/reference/command-line-tools-reference/kube-controller-manager/#kube-controller-manager
--terminated-pod-gc-threshold int32 Default: 12500
Number of terminated pods that can exist before the terminated pod garbage collector starts deleting terminated pods. If <= 0, the terminated pod garbage collector is disabled.
kubectl edit pod kube-controller-manager-<master_name> -n kube-system
it gives me pod is invalid
error after saving the config file.
– Ali Tou
Aug 8 '19 at 19:27
Here is the 'official' guide for how to hard code the threshold(if you do not want to see too many evicted pods): kube-controll-manager
But a known problem is how to have kube-controll-manager installed...
below command will get all evicted pods from the default namespace and delete them
kubectl get pods | grep Evicted | awk '{print$1}' | xargs -I {} kubectl delete pods/{}
Your Answer
Not the answer you're looking for? Browse other questions tagged kubernetes or ask your own question.
Related
Hot Network Questions
-
Gender-specific verbs mess
-
How much better was DEC Alpha than contemporary x86?
-
How do I explain the long life spans of Elves?
-
Primitive underwater melee combat
-
Half my power out, but firing up an appliance turns it back on
-
It's all about the sum of the digits
-
Doubt on how move as black after pawn in e5
-
How to deal with a promotion if you are not sure you want it?
-
Would this hit/miss houserule be balanced with bounded accuracy?
-
New UK passport dual citizenship observation
-
Living next door to Alice
-
Print this maximally long URL
-
Concentric rings on a snub square tiling
-
Casting creatures as spells - searching for the rules
-
How to show a "Yes" for a negative occurrence and "No" for a positive occurrence
-
Am I being ethical or annoying in refusing to 1:1 copy another company's UI for our own?
-
I was playing a tournament and some kids were talking about the game in a foreign language
-
Are screened transistors an endangered species?
-
How to quickly and inexpensively deposit cash?
-
Right before you, I make my mark
-
Can you use your off-handed weapon for your main attack action?
-
Odds of rolling the same results twice on advantage rolls
-
How to generate a random integer array satisfying complex constraints
-
Why did the Allies Invade French North Africa?
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution required. rev 2020.2.6.35996