In the context of the CKA exam and Workloads & Scheduling, Pod Priority and Preemption are mechanisms used to ensure that critical workloads run even when the cluster is under resource pressure.
**Pod Priority** indicates the importance of a Pod relative to others. It is implemented using a non-na…In the context of the CKA exam and Workloads & Scheduling, Pod Priority and Preemption are mechanisms used to ensure that critical workloads run even when the cluster is under resource pressure.
**Pod Priority** indicates the importance of a Pod relative to others. It is implemented using a non-namespaced API object called `PriorityClass`, which maps a specific name to an integer value. A higher integer represents a higher priority. When a user creates a Pod, they specify the `priorityClassName` in the Pod spec. The Kubernetes scheduler uses this value to order Pods in the scheduling queue; higher-priority Pods are processed before lower-priority ones.
**Preemption** occurs when a high-priority Pod is pending but cannot be scheduled because no node has sufficient available resources. In this scenario, the scheduler attempts to free up space by 'preempting' (evicting) lower-priority Pods running on a suitable node. The lower-priority Pods receive a graceful termination signal, and once they are removed and resources are released, the high-priority Pod is scheduled on that node.
For CKA administrators, it is important to understand that there are system-reserved priority classes (`system-node-critical` and `system-cluster-critical`) which ensure core components (like CoreDNS) are not evicted by user workloads. When configuring your own `PriorityClass`, you can also set a `globalDefault` to false or true to control default behavior for Pods without a specified class. Correctly utilizing these features guarantees that mission-critical applications (e.g., payment processing) take precedence over less critical tasks (e.g., batch reporting) during resource contention.
Concept Guide: Pod Priority and Preemption
What is Pod Priority and Preemption? Pod Priority indicates the importance of a Pod relative to other Pods. Preemption is the logic that allows the Kubernetes Scheduler to evict (terminate) running lower-priority Pods to make room for a pending higher-priority Pod when the cluster is resource-constrained.
Why is it Important? In production environments, resources (CPU and Memory) are finite. It is crucial to ensure that mission-critical workloads (like a production database or an API gateway) are scheduled immediately, even if the cluster is currently full of low-priority tasks like batch processing, CI/CD jobs, or development pods. Without priority and preemption, a critical pod might sit in a Pending state indefinitely until resources are freed up naturally.
How it Works The mechanism relies on two steps: definition and enforcement.
1. PriorityClass: This is a non-namespaced object that maps a name to an integer value. The higher the value, the higher the priority. For example, a class named "high-priority" might have a value of 1,000,000. 2. Assignment: Users specify the priorityClassName in the Pod specification. 3. Preemption Logic: When a high-priority Pod is created but no node has sufficient resources to run it, the Scheduler scans the nodes to identify running Pods with lower priority. It then terminates (preempts) those lower-priority Pods to reclaim resources. Once the resources are released, the high-priority Pod is scheduled.
Exam Tips: Answering Questions on Pod Priority and Preemption In the CKA exam, you may be asked to prioritize specific workloads or troubleshoot why a pod isn't scheduling. Keep these strategies in mind:
1. Creating a PriorityClass You must be comfortable writing the YAML for a PriorityClass. It belongs to the scheduling.k8s.io/v1 API group. apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: critical-app value: 1000000 globalDefault: false description: "For critical apps only."
2. Assigning to Pods Don't forget to link the class to the Pod. In the Pod manifest (or Deployment template), add the field priorityClassName: critical-app at the same level as containers or restartPolicy.
3. Understanding Global Default Be careful with the globalDefault boolean. If set to true, every Pod created without a specific priority class name will get this priority. Usually, this is kept false.
4. Troubleshooting If a question asks why a Pod is pending despite having high priority, use kubectl describe pod [pod-name]. Look for the Events section. You might see messages about Preemption failing because of PodDisruptionBudgets or affinity rules that prevent the scheduler from finding a suitable node even after eviction.
5. System Criticality Remember that system components use reserved priority classes (like system-node-critical). Avoid creating custom classes with values exceeding 2 billion, as these are reserved for the system.