📖 Scenario: You are managing a Kubernetes cluster where some applications are more important than others. You want to make sure that when resources are tight, the most important pods get scheduled first by using pod priority and preemption.
🎯 Goal: Learn how to create pod priority classes and assign priorities to pods so that Kubernetes can preempt lower priority pods when scheduling higher priority pods.
📋 What You'll Learn
Create a pod priority class with a specific priority value
Create a pod that uses the priority class
Create a lower priority pod
Observe pod scheduling and preemption behavior
💡 Why This Matters
🌍 Real World
Pod priority and preemption help ensure that critical applications get the resources they need in a busy Kubernetes cluster, improving reliability and user experience.
💼 Career
Understanding pod priority and preemption is essential for Kubernetes administrators and DevOps engineers to manage cluster resources effectively and maintain application uptime.
Progress0 / 4 steps
1
Create a Pod Priority Class
Create a pod priority class named high-priority with a value of 1000 and a globalDefault set to false. Use the kubectl apply -f command with a YAML manifest.
Kubernetes
Hint
Use kind: PriorityClass and set value to 1000.
2
Create a Pod with Lower Priority
Create a pod named low-priority-pod without specifying a priority class. The pod should run the nginx container. Use the kubectl apply -f command with a YAML manifest.
Kubernetes
Hint
Do not set priorityClassName for the low priority pod.
3
Create a Pod with High Priority
Create a pod named important-pod that uses the high-priority priority class. Use the kubectl apply -f command with a YAML manifest. The pod should run the nginx container.
Kubernetes
Hint
Set priorityClassName to high-priority in the pod spec.
4
Observe Pod Scheduling and Preemption
Run kubectl get pods to see the status of the pods. Then run kubectl describe pod low-priority-pod to check if it was preempted when important-pod was scheduled.
Kubernetes
Hint
Use kubectl get pods and kubectl describe pod low-priority-pod to observe scheduling and preemption.
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
Step 1: Understand pod priority concept
Pod priority is used to rank pods by importance for scheduling decisions.
Step 2: Identify scheduling impact
When resources are scarce, higher priority pods are scheduled before lower priority ones.
Final Answer:
To decide which pods get scheduled first when resources are limited -> Option A
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
Step 1: Recall pod spec fields
The priority class is set under the pod's spec using priorityClassName.
Step 2: Verify correct YAML syntax
Correct field is spec.priorityClassName, not metadata or spec.priority.
Final Answer:
spec.priorityClassName: high-priority -> Option D
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
Step 1: Compare pod priorities
Pod A and Pod C have priority 1000, Pod B has 500.
Step 2: Select highest priority pods
Kubernetes schedules pods with highest priority first, so Pod A and Pod C run.
Final Answer:
Pod A and Pod C -> Option B
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
Step 1: Check priority class existence
If the priority class "high-priority" is not defined, the pod cannot use it for preemption.
Step 2: Understand preemption behavior
Preemption requires a valid priority class; missing it disables preemption.
Final Answer:
The priority class "high-priority" is not defined in the cluster -> Option A
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
Step 1: Understand preemption role
When a high priority pod is pending, Kubernetes can preempt lower priority pods to free resources.
Step 2: Apply preemption behavior
Kubernetes stops lower priority pods to schedule the higher priority pod if possible.
Final Answer:
It preempts lower priority pods to free resources for the new pod -> Option C
Quick Check:
High priority pod triggers preemption = B [OK]
Hint: High priority pods preempt lower ones to get scheduled [OK]