Bird
Raised Fist0
Kubernetesdevops~10 mins

Pod priority and preemption in Kubernetes - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the priority class name for a pod.

Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  priorityClassName: [1]
  containers:
  - name: nginx
    image: nginx
Drag options to blanks, or click blank then click option'
Ahigh-priority
Blow-priority
Cmedium-priority
Dno-priority
Attempts:
3 left
💡 Hint
Common Mistakes
Using a priority class name that does not exist in the cluster.
2fill in blank
medium

Complete the command to create a priority class with high priority.

Kubernetes
kubectl create priorityclass [1] --value=1000 --description="High priority class"
Drag options to blanks, or click blank then click option'
Amedium-priority
Blow-priority
Cdefault-priority
Dhigh-priority
Attempts:
3 left
💡 Hint
Common Mistakes
Using a priority class name that does not match the value.
3fill in blank
hard

Fix the error in the pod spec to enable preemption by setting the correct field.

Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: preemptible-pod
spec:
  priorityClassName: high-priority
  [1]: "PreemptLowerPriority"
  containers:
  - name: busybox
    image: busybox
    command: ["sleep", "3600"]
Drag options to blanks, or click blank then click option'
AenablePreemption
BpreemptionPolicy
Cpreemptible
DallowPreemption
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent fields like 'enablePreemption' or 'allowPreemption'.
4fill in blank
hard

Fill both blanks to create a priority class YAML with correct apiVersion and kind.

Kubernetes
apiVersion: [1]
kind: [2]
metadata:
  name: custom-priority
value: 500
globalDefault: false
description: "Custom priority class"
Drag options to blanks, or click blank then click option'
Ascheduling.k8s.io/v1
Bv1
CPriorityClass
DPodPriority
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'v1' as apiVersion or 'PodPriority' as kind.
5fill in blank
hard

Fill in the blanks to write a pod spec that uses a priority class and disables preemption.

Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: no-preempt-pod
spec:
  priorityClassName: [1]
  preemptionPolicy: [2]
  containers:
  - name: app
    image: nginx
    command: ["nginx", "-g", "daemon off;"]
Drag options to blanks, or click blank then click option'
Ahigh-priority
BNever
Creplicas
Dpriority
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replicas' in pod spec (only for deployments).
Setting preemptionPolicy to wrong values.

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