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?
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.
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.
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.
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.
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
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 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With