Sub topic 6
PriorityClass and assigning priority to Pods
This chapter assumes you can apply YAML manifests with kubectl and know what the kube-scheduler and a Pod's resource requests are. QoS classes were covered earlier. Here you will see how to give Pods a priority.
What a PriorityClass is
A PriorityClass is a cluster-scoped object that maps a name to an integer. That integer is the priority of any Pod that uses the name. A higher number means a more important Pod. The scheduler and the kubelet read this number when they decide which Pods to place first, which to remove, and which to evict.
Priority is separate from QoS. Setting a priority does not change a Pod's QoS class, and setting requests and limits does not change its priority.
Create a PriorityClass and use it
The Pod selects a class by name with priorityClassName. The class below also appears with a Pod that uses it.
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000000
globalDefault: false
description: "For latency-sensitive workloads that may preempt lower-priority Pods."
---
apiVersion: v1
kind: Pod
metadata:
name: important-app
spec:
priorityClassName: high-priority
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: "1"
memory: 512MiThe important fields are:
value: the integer priority. User-defined classes can use values up to 1,000,000,000. Larger values are reserved for system classes.globalDefault: iftrue, Pods that name no class get this class's value. Only one class in the cluster may set it.description: free text for people.preemptionPolicy: defaults toPreemptLowerPriority. The next chapters cover what it does.
How the priority reaches the Pod
When you create the Pod, the Priority admission controller looks up the class named in priorityClassName. It copies the integer into spec.priority. After that, the Pod keeps this number even if the class changes.
The flow looks like this:
If you name a class that does not exist, the API server rejects the Pod. If you name no class and no default exists, the priority is 0.
Common errors
- Pod rejected with "no PriorityClass with name ... was found". Create the PriorityClass first, then the Pod.
- Changing a class and expecting running Pods to change. The value is copied at creation. Existing Pods keep the old number. Recreate them to pick up the new one.
- Editing
valueon an existing class. The field is immutable. Create a new class and move workloads to it. - Setting
globalDefault: trueand expecting old Pods to change. It only affects Pods created after the class exists. - Putting
priorityClassNameon a Deployment's top level. It belongs in the Pod template, underspec.template.spec.
Check the result
Run this to confirm what a Pod received:
kubectl describe pod important-app | grep -iE 'priority|qos|nominated'The output shows both Priority and Priority Class Name, plus the QoS class. This confirms that the two are independent.
Exercise
You create a PriorityClass named batch-low with value 100, then change its value to 500 with kubectl apply. Why does the apply fail, and how do you give a running Pod the new value?
Show answer
The value field of a PriorityClass is immutable, so the update is rejected. Create a new class (for example batch-mid with value 500), set priorityClassName to it in the Pod template, and recreate the Pods. A running Pod keeps the integer copied into spec.priority at creation.