Module 5: Preemption Testing

Preemption is the mechanism that gives reserved workloads priority over unreserved ones. When a user with a reservation submits a workload and there aren’t enough free resources, Kueue evicts unreserved workloads to make room.

In this module, you’ll simulate a multi-user GPU contention scenario using the workload Helm chart and observe preemption in action.

Learning objectives

By the end of this module, you’ll be able to:

  • Deploy unreserved workloads that consume GPU resources

  • Trigger preemption by submitting a reserved workload

  • Observe the Kueue admission and eviction process

  • Test preemption with both full GPUs and MIG partitions

Kueue state after reservations

Once users have reserved GPUs through the booking app, the Kueue resource hierarchy includes per-user ClusterQueues with protected quota, and reserved LocalQueues in each namespace:

Kueue Hierarchy with Reservations

The red LocalQueues (user1, user2) point to per-user ClusterQueues with reclaimWithinCohort: Any. The unreserved ClusterQueue’s nominalQuota has been reduced from 8 to 5 GPUs to account for the 3 GPUs reserved.

How preemption works in this environment

Preemption Flow

The preemption model is based on Kueue’s Cohort borrowing rules:

1. Unreserved workloads run using shared Cohort quota
2. User makes a reservation → booking app creates ClusterQueue with nominalQuota
3. User submits workload → ClusterQueue has reclaimWithinCohort: Any
4. Kueue preempts unreserved workloads borrowing from the Cohort
5. Reserved workload gets resources
6. Unreserved workload re-queues, waits for resources

The unreserved ClusterQueue has no reclaim rights, so its workloads can always be preempted. User ClusterQueues have reclaimWithinCohort: Any, meaning they can preempt any workload borrowing from the same Cohort.

Exercise 1: Fill the cluster with unreserved workloads

Acting as: user1
Log in to the OpenShift CLI:

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u user1 -p %password%

First, let’s consume GPU resources with unreserved workloads.

  1. Deploy an unreserved workload requesting 8 full GPUs (all available):

    helm template gpu-deploy oci://quay.io/eformat/gpu-test-workloads -n user-user1 \
      --set kind=Deployment \
      --set name=gpu-fake-gpu \
      --set replicas=1 \
      --set gpuCount=8 \
      --set gpuResourceType=nvidia.com/gpu \
      --set reserved=false \
      | oc -n user-user1 apply -f-

    Expected output:

    deployment.apps/gpu-fake-gpu created
  2. Wait for the deployment to be ready:

    oc -n user-user1 rollout status deployment/gpu-fake-gpu --timeout=60s

    Expected output:

    deployment "gpu-fake-gpu" successfully rolled out
  3. Verify all GPUs are consumed:

    oc get clusterqueue unreserved -o jsonpath='{.status.flavorsUsage}' | jq .

    Expected output:

    {
      "borrowed": "8",
      "name": "nvidia.com/gpu",
      "total": "8"
    }
  4. Verify nvidia-smi shows the GPUs:

    oc -n user-user1 exec $(oc -n user-user1 get pod -l app=gpu-fake-gpu -o name | head -1) -- nvidia-smi

    You should see 8 NVIDIA GB200 NVL GPUs listed in the nvidia-smi output table. Each row represents one simulated GPU with its memory usage and utilization.

  5. You can also check the workload status in the Booking App.

    Unreserved Workload Running with 8 GPUs

Verify

✓ Unreserved deployment is running with 8 GPUs
✓ ClusterQueue shows all GPU resources in use

Exercise 2: Trigger preemption with a reserved workload

We are now going to trigger preemption with a reserved workload. We will create a reserved workload before we book a GPU for today. This gives us a chance to see the preemption happen in action.

Acting as: user2
Log in to the OpenShift CLI:

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u user2 -p %password%

Now deploy a reserved workload from a different user. This simulates a user with a GPU reservation claiming their resources.

  1. Deploy a reserved workload requesting 1 GPU:

    helm template gpu-deploy oci://quay.io/eformat/gpu-test-workloads -n user-user2 \
      --set kind=Deployment \
      --set name=gpu-fake-gpu \
      --set replicas=1 \
      --set gpuCount=1 \
      --set gpuResourceType=nvidia.com/gpu \
      --set reserved=true \
      | oc -n user-user2 apply -f-

    Expected output:

    deployment.apps/gpu-fake-gpu created
  2. The workload will be in a SchedulingGated state as we have not yet booked a GPU for today.

    oc -n user-user2 get pods,workload

    Expected output:

    NAME                                READY   STATUS            RESTARTS   AGE
    pod/gpu-fake-gpu-74868b8b79-4cxdw   0/1     SchedulingGated   0          38s
    
    NAME                                                              QUEUE      RESERVED IN   ADMITTED   FINISHED   AGE
    workload.kueue.x-k8s.io/pod-gpu-fake-gpu-74868b8b79-4cxdw-18555   reserved                                       38s

Acting as: admin
Log in to the OpenShift CLI:

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u admin -p %password%
  1. Watch the preemption happen in the terminal:

    oc get events -A --sort-by='.lastTimestamp' --field-selector reason=Preempted -w

Acting as: user2
Log in to the OpenShift Console at https://console-openshift-console.apps.cluster.example.com with username user2 and password %password%.

  1. Open the GPU Booking > Bookings page in the OpenShift Console and book 1 GPU for today.

  2. The pod will be admitted by Kueue but scheduling now needs to re-run. Delete the pod to trigger scheduling. From the OpenShift Console, navigate to Workloads > Pods and delete the pod.

    Delete Pod
  3. Back on the admin terminal - we now expected to see the preemption event:

    NAMESPACE    LAST SEEN   TYPE     REASON      OBJECT                                             MESSAGE
    user-user1   0s          Normal   Preempted   workload/pod-gpu-fake-gpu-54959878d8-nclg6-a68ff   Preempted to accommodate a workload (UID: 79cd54c4-2146-451a-96c8-5ca1609a451e, JobUID: 7e9fa1f0-3072-4e20-9d4d-54ae8007955f) due to reclamation within the cohort; preemptor path: /unreserved/user-user2; preemptee path: /unreserved/unreserved

    Press Ctrl+C after you see preemption events. Kueue evicts the unreserved workload to free one GPU for the reserved request.

  4. Check the workload status:

    oc get workloads -A -o custom-columns=\
    NAMESPACE:.metadata.namespace,\
    NAME:.metadata.name,\
    QUEUE:.spec.queueName,\
    ADMISSION:.status.admission.clusterQueue,\
    ADMITTED:.status.conditions[0].status

    Expected output - the unreserved workload is not admitted and the reserved workload is admitted:

    NAMESPACE    NAME                                      QUEUE        ADMISSION    ADMITTED
    user-user1   pod-gpu-fake-gpu-54959878d8-m4zdc-84bd2   unreserved   <none>       False
    user-user2   pod-gpu-fake-gpu-74868b8b79-c8hlg-af2e1   reserved     user-user2   True
  5. Verify the reserved workload is running:

    oc -n user-user2 rollout status deployment/gpu-fake-gpu --timeout=60s

    Expected output:

    deployment "gpu-fake-gpu" successfully rolled out
  6. Check nvidia-smi on the reserved workload:

    oc -n user-user2 exec $(oc -n user-user2 get pod -l app=gpu-fake-gpu -o name | head -1) -- nvidia-smi

    You should see the nvidia-smi output for the reserved workload.

  7. We can also check the workload status in the Booking App.

    Reserved Workload Preempted Unreserved Workload

    You should see the reserved workload is running (red) and the preemption event is shown in the console as well.

Verify

✓ Reserved workload preempted the unreserved workload
✓ We saw the preemption event in the terminal
✓ nvidia-smi shows GPU allocation in the reserved workload
✓ We saw the preempted workload in the Booking App

Exercise 3: Test MIG partition preemption

Preemption also works with MIG partitions. Let’s test with MIG-1g.23gb devices. Lets quickly run through the steps to deploy a MIG workload and see the preemption in action.

Acting as: user1
Switch to the user1 CLI context:

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u user1 -p %password%
  1. Deploy an unreserved workload consuming 56 MIG-1g.23gb partitions:

    helm template gpu-deploy oci://quay.io/eformat/gpu-test-workloads -n user-user1 \
      --set kind=Deployment \
      --set name=gpu-fake-23gb \
      --set replicas=1 \
      --set gpuCount=56 \
      --set gpuResourceType=nvidia.com/mig-1g.23gb \
      --set reserved=false \
      | oc -n user-user1 apply -f-
  2. Wait for deployment:

    oc -n user-user1 rollout status deployment/gpu-fake-23gb --timeout=60s
  3. Check the running pods:

    oc -n user-user1 get pods

    Expected output:

    oc get pods
    NAME                             READY   STATUS            RESTARTS   AGE
    gpu-fake-23gb-5d687f5d44-gxncs   1/1     Running           0          7s
    gpu-fake-gpu-54959878d8-m4zdc    0/1     SchedulingGated   0          21m

    We can see the full GPU is SchedulingGated (it is still preempted) and the MIG workload is Running.

  4. We can also check the workload status in the Booking App.

    Unreserved MIG Workload Running with 56 MIG Partitions

    You should see the user2 reserved workload is running (red) and the user1 unreserved MIG workload in (green).

Acting as: user2
Log in to the OpenShift Console at https://console-openshift-console.apps.cluster.example.com with username user2 and password %password%.

  1. Open the GPU Booking > Bookings page in the OpenShift Console and book 8 MIG-1g.23gb partitions for today.

    Reserved Workload Booked 8 MIG-1g.23gb Partitions

Acting as: user2
Switch to the user2 CLI context:

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u user2 -p %password%
  1. Deploy a reserved workload requesting 8 MIG partitions:

    helm template gpu-deploy oci://quay.io/eformat/gpu-test-workloads -n user-user2 \
      --set kind=Deployment \
      --set name=gpu-fake-23gb \
      --set replicas=1 \
      --set gpuCount=8 \
      --set gpuResourceType=nvidia.com/mig-1g.23gb \
      --set reserved=true \
      | oc -n user-user2 apply -f-
  2. Watch preemption and verify both are running:

    oc -n user-user2 rollout status deployment/gpu-fake-23gb --timeout=60s
  3. We should now see both user2 reserved workloads running and user1 unreserved workloads preempted in the Booking App.

    Preempted 2 Unreserved MIG Workloads by Reserved MIG Workload
  4. Check nvidia-smi on the MIG workloads:

    oc -n user-user2 exec $(oc -n user-user2 get pod -l app=gpu-fake-gpu -o name | head -1) -- nvidia-smi
    oc -n user-user2 exec $(oc -n user-user2 get pod -l app=gpu-fake-23gb -o name | head -1) -- nvidia-smi

    Notice the MIG partition size (23 GB) shown in nvidia-smi output.

Verify

✓ Unreserved MIG workload preempted by reserved MIG workload
✓ Both user2 reserved workloads running with correct GPU and MIG partition counts

Exercise 4: Clean up all workloads

user1: Delete workloads

Acting as: user1

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u user1 -p %password%
  1. Remove user1’s test deployments:

    oc -n user-user1 delete deployment gpu-fake-gpu
    oc -n user-user1 delete deployment gpu-fake-23gb

user2: Delete workloads

Acting as: user2

oc login --insecure-skip-tls-verify $(oc whoami --show-server) -u user2 -p %password%
  1. Remove user2’s test deployments:

    oc -n user-user2 delete deployment gpu-fake-gpu
    oc -n user-user2 delete deployment gpu-fake-23gb
  2. Verify all GPU resources are free:

    oc get clusterqueues -o custom-columns=\
    NAME:.metadata.name,\
    ADMITTED:.status.admittedWorkloads

    All ClusterQueues should show 0 admitted workloads.

  3. user2: Cancel booking

    Acting as: user2
    Return to the OpenShift Console as user2.

  4. Navigate to GPU Booking > Bookings and click My Bookings.

  5. Click Cancel All to remove the GPU reservation, then click Confirm.

Verify

✓ All test deployments deleted
✓ GPU resources fully released

Module summary

What you accomplished:

  • Filled the cluster with unreserved GPU workloads

  • Triggered preemption by submitting a reserved workload

  • Observed Kueue evicting unreserved workloads to honor reserved quotas

  • Tested preemption with both full GPUs and MIG partitions

Key takeaways:

  • Reserved workloads always win over unreserved ones through Kueue’s reclaimWithinCohort: Any policy

  • Preemption is automatic — Kueue handles eviction without manual intervention

  • MIG partitions follow the same preemption model as full GPUs

  • The booking app creates the Kueue resources that make preemption possible; users only interact with the calendar

  • Unreserved workloads are not lost — they re-queue and resume when resources become available

Next: Head to the Conclusion for a summary of what you learned and resources to continue your journey.