Priority Mechanisms in Kubernetes: QoS and PriorityClass
PriorityClass
A PriorityClass is a cluster-wide (non-namespaced) resource from the scheduling.k8s.io API group. It defines a mapping between a priority name and an integer value. Higher numbers indicate higher priority.
This is an example:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000000
globalDefault: false
description: "Used for critical Pods such as monitoring agents"
preemptionPolicy: PreemptLowerPriority
The fields are:
value — An integer between
-2147483648and1000000000. Higher values represent higher priority. Values above 1 billion are reserved for Kubernetes system Pods.globalDefault — When set to
true, this PriorityClass becomes the default for all Pods that do not explicitly define a priority. Only one PriorityClass in the cluster can have this field set.description — A human-readable note explaining when to use this PriorityClass.
preemptionPolicy — Determines whether Pods in this class can preempt lower-priority Pods. The options are:
PreemptLowerPriority(default): Allows eviction of lower-priority Pods.Never: Pods with this class cannot preempt others, but they are still scheduled before lower-priority Pods once resources are available.
ℹ️ In multi-tenant clusters, a malicious user could create Pods with very high priorities and evict others. Cluster administrators can prevent this using ResourceQuotas that restrict access to specific PriorityClasses.
Non-preempting PriorityClass
Starting with Kubernetes v1.24, you can create non-preempting PriorityClasses. These Pods wait in the scheduling queue ahead of lower-priority Pods, but never evict them.
Example:
apiVersionCloud-Native Microservices With Kubernetes - 2nd Edition
A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in KubernetesEnroll now to unlock all content and receive all future updates for free.
