0
0
KubernetesConceptBeginner · 4 min read

Kubernetes Priority Class: What It Is and How It Works

In Kubernetes, a 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.

yaml
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
Output
PriorityClass "high-priority" created Pod "important-pod" created with priority 1000
🎯

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.

Key Takeaways

PriorityClass controls pod importance for scheduling and eviction in Kubernetes.
Higher numeric priority means the pod is more important and less likely to be evicted.
Assign PriorityClass to critical pods to ensure they run reliably under resource pressure.
Use lower priority for non-critical workloads to free resources when needed.
You can create custom PriorityClasses with different priority values and descriptions.