Kubernetes Priority Class: What It Is and How It Works
PriorityClass defines the importance of pods to influence scheduling and eviction decisions. Pods with higher priority classes are scheduled before lower priority ones and are less likely to be evicted when resources are scarce.How It Works
Think of Kubernetes as a busy airport where planes (pods) need to land on limited runways (nodes). The PriorityClass acts like a VIP pass that tells the air traffic controller which planes should land first when space is tight.
Each pod can be assigned a priority class that has a numeric value. The higher the number, the more important the pod is. When the cluster runs low on resources, Kubernetes uses these priority values to decide which pods to keep running and which to stop (evict) to free up space.
This system helps ensure critical applications stay online while less important ones can be paused or delayed during high demand.
Example
This example shows how to create a PriorityClass and assign it to a pod.
apiVersion: scheduling.k8s.io/v1 kind: PriorityClass metadata: name: high-priority value: 1000 globalDefault: false description: "This priority class is for high priority pods." --- apiVersion: v1 kind: Pod metadata: name: important-pod spec: priorityClassName: high-priority containers: - name: nginx image: nginx
When to Use
Use PriorityClass when you want to control which pods get resources first during high demand or node failures. For example:
- Critical system components like monitoring or logging agents should have high priority to stay running.
- Batch jobs or less important workloads can have lower priority so they get evicted first if needed.
- During cluster autoscaling, priority helps decide which pods to schedule first.
This helps keep your important services reliable and responsive.
Key Points
- PriorityClass assigns numeric priority to pods.
- Higher priority pods are scheduled before lower priority ones.
- Pods with lower priority are evicted first when resources run out.
- It helps manage resource allocation during cluster stress.
- Default priority can be set with
globalDefault.