Bird
Raised Fist0
Kubernetesdevops~10 mins

Pod priority and preemption in Kubernetes - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Pod priority and preemption
Pod submitted
↓
Check node resources
↓
Enough resources?
Yes→Schedule pod
No↓
Check pod priorities
↓
Preempt lower priority pods?
Yes→Evict lower priority pods
No↓
Pod remains pending
When a pod is submitted, Kubernetes checks if nodes have enough resources. If not, it tries to preempt lower priority pods to make room for higher priority pods.
Execution Sample
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: high-priority-pod
spec:
  priorityClassName: high-priority
  containers:
  - name: app
    image: nginx
This pod manifest defines a pod with a high priority class to influence scheduling and preemption.
Process Table
StepActionNode Resources AvailablePod PriorityLower Priority Pods FoundPreemption ActionPod Scheduling Result
1Pod submittedCPU: 2 cores, Memory: 4Gi freeHighN/AN/ACheck resources
2Check node resourcesCPU: 2 cores, Memory: 4Gi freeHighN/AN/ANot enough resources for pod (needs 3 cores)
3Check pod prioritiesCPU: 2 cores, Memory: 4Gi freeHighYes, low-priority pods using 2 coresEvict low-priority podsEvicted pods to free resources
4Schedule podCPU: 3 cores free after evictionHighN/AN/APod scheduled successfully
5EndCPU: 1 core free after pod scheduledHighN/AN/AScheduling complete
💡 Pod scheduled after evicting lower priority pods to free resources
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Node CPU Free2 cores2 cores3 cores1 core1 core
Pod PriorityN/AHighHighHighHigh
Lower Priority Pods PresentN/AN/AYesNoNo
Pod ScheduledNoNoNoYesYes
Key Moments - 3 Insights
Why does Kubernetes evict pods before scheduling a new pod?
Kubernetes evicts lower priority pods to free resources for higher priority pods, as shown in step 3 where eviction happens to make room.
What happens if no lower priority pods are found during scheduling?
If no lower priority pods exist to evict, the new pod remains pending, as the scheduler cannot free resources (not shown in this trace but implied after step 2).
Does pod priority affect scheduling if resources are already sufficient?
No, if resources are enough, the pod schedules directly without preemption, as in step 1 when resources are checked.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Kubernetes evict lower priority pods?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Preemption Action' column in the execution table.
According to the variable tracker, what is the node CPU free after step 4?
A2 cores
B3 cores
C1 core
D4 cores
💡 Hint
Look at the 'Node CPU Free' row under 'After Step 4' in the variable tracker.
If the pod priority was low instead of high, what would happen in the execution table?
APod would remain pending without eviction
BLower priority pods would be evicted
CPod would be scheduled immediately
DScheduler would increase node resources
💡 Hint
Refer to the 'Pod Priority' and 'Preemption Action' columns in the execution table.
Concept Snapshot
Pod priority and preemption in Kubernetes:
- Pods have priority classes (high, low, etc.)
- Scheduler checks node resources before placing pods
- If resources insufficient, scheduler evicts lower priority pods
- Eviction frees resources for higher priority pods
- If no eviction possible, pod stays pending
Full Transcript
When a pod is submitted, Kubernetes checks if nodes have enough resources to run it. If resources are enough, the pod is scheduled immediately. If not, Kubernetes looks for lower priority pods running on nodes. It evicts those lower priority pods to free resources for the higher priority pod. After eviction, the pod is scheduled. If no lower priority pods can be evicted, the pod remains pending until resources free up. This process ensures important pods get resources first.

Practice

(1/5)
1. What is the main purpose of pod priority in Kubernetes?
easy
A. To decide which pods get scheduled first when resources are limited
B. To assign network policies to pods
C. To control pod security settings
D. To manage pod storage volumes

Solution

  1. Step 1: Understand pod priority concept

    Pod priority is used to rank pods by importance for scheduling decisions.
  2. Step 2: Identify scheduling impact

    When resources are scarce, higher priority pods are scheduled before lower priority ones.
  3. Final Answer:

    To decide which pods get scheduled first when resources are limited -> Option A
  4. Quick Check:

    Pod priority controls scheduling order = A [OK]
Hint: Pod priority ranks pods for scheduling under resource limits [OK]
Common Mistakes:
  • Confusing priority with security or network policies
  • Thinking priority controls storage or volumes
  • Assuming priority affects pod runtime behavior
2. Which YAML field correctly assigns a priority class to a pod?
easy
A. spec.priority: high-priority
B. metadata.priorityClass: high-priority
C. metadata.priorityClassName: high-priority
D. spec.priorityClassName: high-priority

Solution

  1. Step 1: Recall pod spec fields

    The priority class is set under the pod's spec using priorityClassName.
  2. Step 2: Verify correct YAML syntax

    Correct field is spec.priorityClassName, not metadata or spec.priority.
  3. Final Answer:

    spec.priorityClassName: high-priority -> Option D
  4. Quick Check:

    Priority class set in spec.priorityClassName = C [OK]
Hint: Use spec.priorityClassName to assign priority class in pod YAML [OK]
Common Mistakes:
  • Placing priorityClassName under metadata instead of spec
  • Using spec.priority instead of priorityClassName
  • Misspelling the field name
3. Given these pods with priorities: Pod A (priority 1000), Pod B (priority 500), Pod C (priority 1000). If resources are limited and only two pods can run, which pods will Kubernetes schedule?
medium
A. Pod B and Pod C
B. Pod A and Pod C
C. Pod A and Pod B
D. Pod B only

Solution

  1. Step 1: Compare pod priorities

    Pod A and Pod C have priority 1000, Pod B has 500.
  2. Step 2: Select highest priority pods

    Kubernetes schedules pods with highest priority first, so Pod A and Pod C run.
  3. Final Answer:

    Pod A and Pod C -> Option B
  4. Quick Check:

    Highest priority pods scheduled = A [OK]
Hint: Schedule pods with highest priority first when resources are limited [OK]
Common Mistakes:
  • Choosing pods with lower priority over higher
  • Assuming all pods run regardless of resources
  • Ignoring equal priority pods
4. You created a pod with priorityClassName: "high-priority" but it is not preempting lower priority pods when scheduled. What could be the reason?
medium
A. The priority class "high-priority" is not defined in the cluster
B. Pod preemption is disabled by default in Kubernetes
C. The pod spec is missing resource requests
D. The pod is running on a node with no other pods

Solution

  1. Step 1: Check priority class existence

    If the priority class "high-priority" is not defined, the pod cannot use it for preemption.
  2. Step 2: Understand preemption behavior

    Preemption requires a valid priority class; missing it disables preemption.
  3. Final Answer:

    The priority class "high-priority" is not defined in the cluster -> Option A
  4. Quick Check:

    Undefined priority class blocks preemption = D [OK]
Hint: Ensure priority class exists before expecting preemption [OK]
Common Mistakes:
  • Assuming preemption is disabled by default
  • Ignoring missing resource requests impact
  • Not checking node pod status
5. You have a cluster with pods of different priorities. A new pod with priority 2000 is pending due to lack of resources. How does Kubernetes handle this situation?
hard
A. It waits until resources are manually freed without preemption
B. It schedules the new pod alongside others, causing resource overcommit
C. It preempts lower priority pods to free resources for the new pod
D. It deletes the new pod automatically due to insufficient resources

Solution

  1. Step 1: Understand preemption role

    When a high priority pod is pending, Kubernetes can preempt lower priority pods to free resources.
  2. Step 2: Apply preemption behavior

    Kubernetes stops lower priority pods to schedule the higher priority pod if possible.
  3. Final Answer:

    It preempts lower priority pods to free resources for the new pod -> Option C
  4. Quick Check:

    High priority pod triggers preemption = B [OK]
Hint: High priority pods preempt lower ones to get scheduled [OK]
Common Mistakes:
  • Thinking Kubernetes waits without preemption
  • Assuming resource overcommit happens automatically
  • Believing new pods get deleted if pending
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard