7

From PodInterface the two operations Delete and Evict seems having the same effect: deleting the old Pod and creating a new Pod.

If the two operations have the same effect, why do we need two API to delete a Pod and create a new one?

flyer
  • 9,280
  • 11
  • 46
  • 62

2 Answers2

10

Deletion of a pod is done by an end user and is a normal activity. It means the pod will be deleted from ETCD and kubernetes control plane. Unless there is a higher level controller such as deployment, daemonset, statefulset etc the pod will not be created again and scheduled to a kubernetes worker node.

Eviction happens if resource consumption by pod is exceeded the limit and kubelet triggers eviction of the pod or a user performs kubectl drain or manually invoking the eviction API. It's generally not not a normal activity .Sometimes evicted pods are not automatically deleted from ETCD and kubernetes control plane. Unless there is a higher level controller such as deployment, daemonset, statefulset etc the evicted pod will not be created again and scheduled to a kubernetes worker node.

It's preferable to use delete instead of evict because evict comes with more risk compared to delete because eviction may lead to in some cases, an application to a broken state if the replacement pod created by the application’s controller(deployment etc.) does not become ready, or if the last pod evicted has a very long termination grace period

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • 3
    It's worth noting the *reason* for an eviction. This usually happens because a pod has exceeded it's resource maximum. It is an autonomous action taken by the kubelet scheduler, rather than a commanded action from another process. – SiHa Jun 09 '20 at 08:21
  • 1
    Eviction could be controlled by Pod Disruption budget and documentation says that "Cluster managers and hosting providers should use tools which respect PodDisruptionBudgets by calling the Eviction API instead of directly deleting pods or deployments." So it depends on goal you want to achieve. – tamerlaha Jan 05 '21 at 16:24
2

Pod evict operation (assuming you're referring to the Eviction API) is a sort of smarter delete operation, which respects PodDisruptionBudget and thus it does respect the high-availability requirements of your application (as long as PodDisruptionBudget is configured correctly). Normally you don't manually evict a pod, however the pod eviction can be initiated as a part of a node drain operation (which can be manually invoked by kubectl drain command or automatically by the Cluster Autoscaler component).

Pod delete operation on the other hand doesn't respect PodDisruptionBudget and thus can affect availability of your application. As opposite to the evict operation this operation is normally invoked manually (e.g. by kubectl delete command).

Also besides the Eviction API, pods can be evicted by kubelet due to Node-pressure conditions, in which case PodDisruptionBudget is not respected by Kubernetes (see Node-pressure Eviction)

victorm1710
  • 1,263
  • 14
  • 11