Introduction
The Priority plugin allows Volcano to schedule Pods and Jobs based on their assigned priority. It introduces preemptive capabilities: if a high-priority Job is submitted and the cluster lacks sufficient resources, Volcano will preempt (evict) lower-priority Jobs to free up resources for the high-priority Job. This is essential for ensuring that critical workloads always run.
Environment setup
Update scheduler configmap
- Ensure the
priorityplugin is enabled in yourvolcano-scheduler-configmap. Ensure the
preemptandreclaimactions are enabled if you want high-priority jobs to evict lower-priority ones.kind: ConfigMap apiVersion: v1 metadata: name: volcano-scheduler-configmap namespace: volcano-system data: volcano-scheduler.conf: | actions: "enqueue, allocate, preempt, reclaim, backfill" tiers: - plugins: - name: priority - name: gang
How to use Priority Plugin
To use the Priority plugin, you must first create a PriorityClass object in Kubernetes, and then assign that PriorityClass to your vcjob or Pods.
Step 1: Create Priority Classes
Create a file named priority-classes.yaml:
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000000
globalDefault: false
description: "This priority class should be used for critical service pods only."
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: low-priority
value: 1000
globalDefault: false
description: "This priority class should be used for background data processing."
Step 2: Create Jobs with Priorities
Create a file named priority-jobs.yaml:
apiVersion: batch.volcano.sh/v1alpha1
kind: Job
metadata:
name: low-priority-job
spec:
minAvailable: 1
schedulerName: volcano
priorityClassName: low-priority
tasks:
- replicas: 5
name: worker
template:
spec:
containers:
- image: nginx
name: nginx
resources:
requests:
cpu: "2"
restartPolicy: OnFailure
---
apiVersion: batch.volcano.sh/v1alpha1
kind: Job
metadata:
name: high-priority-job
spec:
minAvailable: 1
schedulerName: volcano
priorityClassName: high-priority
tasks:
- replicas: 2
name: worker
template:
spec:
containers:
- image: nginx
name: nginx
resources:
requests:
cpu: "2"
restartPolicy: OnFailure
Verification
- Assume your cluster has exactly 10 CPUs available.
Apply the PriorityClasses:
kubectl apply -f priority-classes.yamlApply only the low priority job first:
# Extract and apply the low-priority-job from priority-jobs.yaml kubectl apply -f priority-jobs.yamlWait for the
low-priority-jobpods to start running. They will consume all 10 CPUs (5 replicas * 2 CPUs).Now, monitor the pods:
kubectl get pods -wThe
high-priority-jobis applied. Because the cluster is full, Volcano will notice thehigh-priority-jobis waiting and will trigger thepreemptaction.You will observe that two
low-priority-jobpods are evicted (terminated) to free up 4 CPUs. Immediately after, the twohigh-priority-jobpods will be scheduled and transition toRunning.