What will happen to evicted pods in kubernetes?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Kubernetes Pod Eviction: A Detailed Examination
Pods in Kubernetes are the smallest deployable units managed by the cluster. However, there are circumstances when pods are evicted, meaning they are removed from a node due to various reasons. Understanding what happens to evicted pods and why eviction occurs is crucial for maintaining the stability and reliability of applications running in a Kubernetes environment.
What Triggers Pod Eviction?
Pod eviction can be triggered by:
- Resource Constraints: When a node runs out of resources like CPU or memory, Kubernetes may evict pods to free up resources for other critical workloads.
- Node Undersizing: If a node becomes too small to fit all scheduled pods due to increased demand or inefficient scheduling.
- Node Maintenance and Upgrades: Nodes undergoing maintenance may have their pods evicted and rescheduled elsewhere.
- Quality of Service (QoS) Policies: Lower priority or best-effort pods can be evicted in favor of higher priority pods needing the resources.
- Node Preemption: High-priority pods preempt lower-priority ones, leading to eviction.
- Taint and Tolerations: If a taint on a node is not tolerated by a pod, the pod can be evicted.
Understanding Pod Eviction Process
- Eviction Signals: Kubernetes utilizes multiple signals to determine whether a pod should be evicted, such as disk pressure, memory pressure, and custom metrics defined by the cluster's administrators.
- Graceful Eviction: When a pod is evicted, Kubernetes tries to do so gracefully by sending a termination signal to the containers, allowing them to run termination hooks and perform cleanup actions if configured.
- Scheduler's Role: The Kubernetes scheduler tries to find a new node for the evicted pod, respecting the pod's resource requests, constraints, and affinity settings.
Examples and Technical Explanation
Example 1: Resource Constraint Eviction
Consider a node that runs multiple pods with varying resource requirements. Suppose the node's available memory drops below a critical threshold due to a spike in usage by a particular pod. Kubernetes may choose to evict the less critical best-effort QoS pods. The evicted pods are then set to a Pending state, waiting for the scheduler to relocate them.
Example 2: Taint and Toleration
In scenarios where nodes are tainted due to maintenance needs, pods not tolerating these conditions will be evicted:
Pods that do not have the matching toleration in their specification will be evicted or not scheduled on such nodes.
Handling Evicted Pods
To handle evicted pods efficiently, consider the following:
- Cluster Autoscaler: Ensure you have a Cluster Autoscaler set up to automatically resize your cluster by adding or removing nodes in response to load.
- Pod Disruption Budgets (PDBs): Use PDBs to specify the number of replicas allowed to be evicted simultaneously, thus maintaining application availability during disturbances.
- Resource Quotas: Properly define resource requests and limits to prevent resource starvation and unexpected evictions.
- Monitor and Log: Use monitoring tools to set alerts on node saturation levels. Log activities related to pod eviction for further analysis.
Key Points Summary
| Aspect of Eviction | Detail |
| Triggers | Resource constraints, node maintenance, quality of service policies, taints and tolerations |
| Signal Types | Disk pressure, memory pressure, custom-defined metrics |
| Handling Strategies | Use Cluster Autoscaler, define Pod Disruption Budgets, set resource quotas, monitor logs and activities |
| Resource Eviction Order | High-priority pods replace lower-priority pods, best-effort QoS pods are typically evicted first |
| New Scheduling | Evicted pods enter Pending state and await rescheduling by the Kubernetes scheduler, respecting all constraints and affinities |
| Graceful Shutdown | Kubernetes sends termination signals allowing pods to execute termination hooks and cleanup tasks |
In conclusion, evicted pods in Kubernetes is an essential mechanism to ensure the availability and performance of applications. Properly managing resources, setting up effective monitoring, and implementing autoscaling strategies are key practices that can help mitigate the impact of pod evictions.

