> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Spot capacity with SUNK

> Run interruptible Slurm jobs on Spot Node Pools, where SUNK requeues them before CoreWeave reclaims the Nodes

[SUNK Standard](https://docs.coreweave.com/products/sunk.md)

[SUNK Self-Service](https://docs.coreweave.com/products/sunk/about-self-service-sunk.md)

[Spot Node Pools](https://docs.coreweave.com/platform/capacity-plans/spot-node-pools.md) provide preemptible capacity that CoreWeave can reclaim when it needs the capacity elsewhere. SUNK runs Slurm nodes on Spot Nodes the same way it runs them on on-demand Nodes. When CoreWeave announces a preemption, the SUNK Syncer requeues jobs off the Spot node before CoreWeave drains the Node. A requeued job keeps its job ID and starts again from the beginning when capacity is available. Jobs that checkpoint lose only the work since their last checkpoint.

In this guide, you give Spot capacity its own NodeSet and Slurm partition. Jobs that can tolerate interruption run in the Spot partition, and jobs that can't run in other partitions. You also configure how SUNK handles running jobs when a Spot Node is reclaimed.

> [!NOTE]
>
> In SUNK, Slurm **nodes** run in Kubernetes Pods. These aren't the same as Kubernetes **Nodes**, which are the worker machines that run the Pods. To distinguish between the two, this documentation capitalizes Kubernetes Nodes, while Slurm nodes aren't capitalized.

## How SUNK handles a Spot preemption

When CoreWeave selects a Spot Node for preemption, it follows the [preemption timeline](https://docs.coreweave.com/platform/capacity-plans/spot-node-pools.md#instance-preemption). It cordons the Node and adds the label `qos.coreweave.cloud/pending-preemption: "true"`, then drains the Node when the warning window ends. SUNK uses that window to move Slurm jobs off the node while it's still running:

1. The warning label triggers the [Syncer](https://docs.coreweave.com/products/sunk/discover_sunk/syncer.md)'s preemption controller. The cordon also makes the Syncer drain the Slurm node, so Slurm schedules no new jobs on it.
2. The controller confirms that the Slurm node is in the `DRAIN` state, then finds every Slurm job running on it.
3. The Syncer requeues the job. Slurm sends `SIGTERM` to the job, waits for `KillWait` seconds, sends `SIGKILL`, and then runs the Epilog. The job returns to the queue in the `PENDING` state with the same job ID. If Slurm can't requeue the job, the Syncer cancels it by default, so it also ends cleanly while the node is still up.
4. When the warning window ends, CoreWeave drains the Kubernetes Node, and the Syncer sets the Slurm node to `DOWN`. A job still running at that point ends as `NODE_FAIL`, without an Epilog. If the job is eligible for requeue, Slurm then requeues it, the same way it does after any [node failure](https://docs.coreweave.com/products/sunk/run_workloads/checkpoint-and-restart.md).

> [!WARNING]
>
> SUNK might not get the whole Spot preemption warning window. Checkpoint regularly during normal operation, so a job that runs out of time loses little work. For how long the window lasts, see the [preemption timeline](https://docs.coreweave.com/platform/capacity-plans/spot-node-pools.md#instance-preemption).

A requeued job can start again on any node in its partition. If it was submitted only to the Spot partition, it waits there until Spot capacity returns.

The Syncer skips allocations made by the [SUNK Pod Scheduler](https://docs.coreweave.com/products/sunk/run_workloads/schedule-kubernetes-pods.md). It doesn't requeue or cancel them, and their Pods stop when CoreWeave drains the Node.

## Prerequisites

Before you begin, make sure you have the following:

* A SUNK cluster. Spot capacity works with both [SUNK Self-Service](https://docs.coreweave.com/products/sunk/about-self-service-sunk.md) and SUNK Standard.
* Spot capacity for your instance type in the cluster's Availability Zone. Check with [Capacity Finder](https://docs.coreweave.com/platform/capacity-plans/capacity-finder.md) before you provision.
* For SUNK Standard, `kubectl` access to the CoreWeave Kubernetes Service (CKS) cluster with permission to create Node Pools, and write access to the Slurm Helm chart values.

## Add Spot capacity on SUNK Self-Service

On a SUNK Self-Service cluster, add an entry to `spec.nodes` with `computeClass: spot`. The [out-of-band operator](https://docs.coreweave.com/products/sunk/discover_sunk/self-service-architecture.md) creates a Spot Node Pool and a NodeSet for that entry and binds the NodeSet to that Node Pool by name. On-demand and Spot capacity therefore never share a NodeSet. In this example, replace `CLUSTER_NAME` with the name of your `SunkCluster`:

```yaml title="SunkCluster with on-demand and Spot capacity" theme={"system"}
apiVersion: sunk.coreweave.com/v1alpha1
kind: SunkCluster
metadata:
  name: CLUSTER_NAME
spec:
  nodes:
    - name: cpu-control-plane
      instanceType: cd-gp-a192-genoa
      count: 3
      controlPlane: true
    - name: h100
      instanceType: gd-8xh100ib-i128
      count: 4
    - name: h100-spot
      instanceType: gd-8xh100ib-i128
      count: 8
      computeClass: spot
```

`computeClass` accepts `default` or `spot`. It defaults to `default`, the compute class for Reserved and On-Demand capacity. You can't change it after you create the entry, and control-plane entries can't use `spot`. To move a node group between on-demand and Spot capacity, add a new entry and scale the old one to `0`. For every field in a `spec.nodes` entry, see [NodeSpec](https://docs.coreweave.com/products/sunk/reference/sunkcluster-reference.md#nodespec).

SUNK creates a Slurm partition for each NodeSet, named after the entry, so this example produces `h100` and `h100-spot` partitions. SUNK also creates an `all` partition that contains every node and is the default partition. A job submitted without `-p` can therefore run on Spot nodes. Ask users to submit jobs that can't be interrupted to an on-demand partition, such as `-p h100`.

SUNK Self-Service requeues jobs on Spot nodes with the default preemption-handling settings.

## Add Spot capacity on SUNK Standard

On SUNK Standard, you create the Spot Node Pool yourself and add a NodeSet for it in the Slurm chart values. Give Spot capacity its own Node Pool and its own NodeSet rather than mixing it with on-demand capacity. A separate NodeSet gets its own partition, and jobs choose Spot capacity by partition. A taint on the Spot Node Pool keeps every Pod that doesn't explicitly tolerate it, including the on-demand NodeSet's `slurmd` Pods, off the Spot Nodes.

### Create a Spot Node Pool

Create a Node Pool with `computeClass: spot`, and add a taint to its Nodes. CoreWeave doesn't taint Spot Nodes, so add the taint yourself. Use the key `sunk.coreweave.com/compute-class` with the Node Pool's compute class, `spot`, as the value. CKS drops Node Pool labels in the reserved `coreweave.com` and `coreweave.cloud` namespaces, but applies taints in those namespaces to the Nodes:

```yaml title="slurm-h100-spot-nodepool.yaml" theme={"system"}
apiVersion: compute.coreweave.com/v1alpha1
kind: NodePool
metadata:
  name: slurm-h100-spot
spec:
  computeClass: spot
  instanceType: gd-8xh100ib-i128
  targetNodes: 8
  nodeTaints:
    - key: sunk.coreweave.com/compute-class
      value: spot
      effect: NoSchedule
```

```bash theme={"system"}
kubectl apply -f slurm-h100-spot-nodepool.yaml
```

You don't need to add a label to find Spot Nodes. CoreWeave labels every Node with its compute class, `compute.coreweave.com/compute-class`, set to `spot` or `default`. The NodeSet in the following section selects on that label.

You can't change `computeClass` after you create the Node Pool. For the rest of the Node Pool spec, see [Create a Node Pool](https://docs.coreweave.com/products/cks/nodes/create.md). For why taints belong on the Node Pool rather than on individual Nodes, see [Dedicate a Node Pool to a NodeSet](https://docs.coreweave.com/products/sunk/deploy_sunk/bind-nodesets-to-node-pools.md#dedicate-a-node-pool-to-a-nodeset).

### Create a NodeSet for the Spot Node Pool

Add a node definition under `compute.nodes` that tolerates the Spot taint and requires Nodes whose compute class is `spot`. The toleration matches the taint's `spot` value with `operator: Equal`, so the NodeSet tolerates only Spot Nodes, not Nodes tainted with a different compute class:

```yaml title="On-demand and Spot NodeSets" theme={"system"}
compute:
  nodes:
    h100:
      enabled: true
      definitions:
        - gd-8xh100ib-i128
    h100-spot:
      enabled: true
      definitions:
        - gd-8xh100ib-i128
      tolerations:
        - key: sunk.coreweave.com/compute-class
          operator: Equal
          value: spot
          effect: NoSchedule
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: compute.coreweave.com/compute-class
                    operator: In
                    values:
                      - spot
```

The on-demand `h100` node definition doesn't tolerate the Spot taint, so its `slurmd` Pods never land on Spot Nodes, even without an affinity of its own. For more information, see [Bind NodeSets to Node Pools for SUNK Standard](https://docs.coreweave.com/products/sunk/deploy_sunk/bind-nodesets-to-node-pools.md).

With `partitions.auto` enabled (the default), SUNK creates one partition for each NodeSet, named after the NodeSet. The Slurm chart names each NodeSet `RELEASE_NAME-NODE_NAME`, where `NODE_NAME` is the node's key under `compute.nodes`, so with a Helm release named `slurm`, this example produces `slurm-h100` and `slurm-h100-spot` partitions. To confirm the names, run `sinfo` on a login node.

### Keep other jobs off Spot nodes

The automatic partitions already separate the two kinds of capacity. Jobs submitted to the on-demand partition, `slurm-h100` in this example, never run on Spot nodes, so you don't need to define a partition of your own.

By default, SUNK also creates an `all` partition that contains every node, including Spot nodes. Unless another partition is marked as the default, `all` is the default partition, so a job submitted without `-p` can run on a Spot node. Ask users to submit jobs that can't be interrupted to an on-demand partition.

To require every job to choose a partition, disable the `all` partition:

```yaml title="Disable the all partition" theme={"system"}
partitions:
  all:
    enabled: false
```

With no default partition, Slurm rejects a job submitted without `-p`. This also applies to Pods scheduled by the SUNK Pod Scheduler without the `sunk.coreweave.com/partition` annotation. For more information about partitions, see [`partitions`](https://docs.coreweave.com/products/sunk/reference/slurm-parameters#partitions).

## Configure preemption handling

The Syncer's preemption controller is on by default. It requeues Slurm jobs on any Node whose warning label is set to `"true"`. On SUNK Standard, you configure it in `syncer.config.syncer.nodesetUpdateJobPreemption` in the Slurm chart values. For every field and its default, see [`syncer.config.syncer`](https://docs.coreweave.com/products/sunk/reference/slurm-parameters#syncer--config--syncer) in the Slurm parameters reference. SUNK Self-Service doesn't expose these fields, so SUNK Self-Service clusters always use the defaults, so jobs that Slurm can't requeue are canceled. These settings apply only to Spot preemption warnings, not to NodeSet rolling updates or scale-down.

### Jobs that Slurm cannot requeue

Slurm can't requeue jobs submitted with `--no-requeue`, jobs submitted without `--requeue` on a cluster with `JobRequeue=0`, and interactive `salloc` or `srun` allocations. With the default `syncer.config.syncer.nodesetUpdateJobPreemption.onNotRequeueable: cancel`, these jobs end as `CANCELLED` and run their Epilog. Set `onNotRequeueable: ignore` only if you want them to keep running until the Node is removed.

### Set the checkpoint window

`KillWait` is the time Slurm gives a job to checkpoint and exit. It's the time between `SIGTERM` and `SIGKILL`, and it defaults to 30 seconds on SUNK. To give jobs more time to checkpoint, raise it in `slurmConfig` on SUNK Standard, or in `spec.slurmConfig` on SUNK Self-Service:

```yaml theme={"system"}
slurmConfig:
  KillWait: "60"
```

Raising `KillWait` doesn't extend the warning window. If CoreWeave drains the Node while the job is still checkpointing, the job's processes stop immediately. The job is already requeued, so it still runs again, but its checkpoint might be only partially written. Keep `KillWait` plus the Epilog well under the warning window. Keep the previous checkpoint until a new one is completely written, so an interrupted write doesn't leave the job with nothing to resume from.

`KillWait` applies to every job termination, including `scancel` and time limits, not only to Spot preemption.

## Submit a job to Spot capacity

A job that runs on Spot capacity must survive being stopped and started again. We recommend that you submit a job with `--requeue`, so it stays eligible for requeue even if the cluster's `JobRequeue` default changes. `--requeue` isn't required. By default, a job that Slurm can't requeue is canceled instead, as described in [Jobs that Slurm cannot requeue](#jobs-that-slurm-cannot-requeue). Also use `--open-mode=append`, so a requeued run doesn't overwrite its earlier output.

Target Spot capacity with the Spot partition. In this example, replace `SPOT_PARTITION` with the name of the Spot partition, such as `h100-spot` on SUNK Self-Service or `slurm-h100-spot` on SUNK Standard. Replace `TRAINING_COMMAND` with your training command, which must resume from its latest checkpoint:

```bash title="spot-training.sbatch" theme={"system"}
#!/bin/bash
#SBATCH --job-name=spot-training
#SBATCH --partition=SPOT_PARTITION
#SBATCH --requeue
#SBATCH --open-mode=append
#SBATCH --nodes=2
#SBATCH --gres=gpu:8

srun TRAINING_COMMAND
```

To let a job use whichever capacity becomes available first, list both partitions. Slurm runs the job in the partition that can start it earliest. Replace `ON_DEMAND_PARTITION` with the name of an on-demand partition, such as `h100` on SUNK Self-Service:

```bash theme={"system"}
sbatch --partition=SPOT_PARTITION,ON_DEMAND_PARTITION spot-training.sbatch
```

The training code must handle `SIGTERM` by saving a checkpoint and exiting within `KillWait`. On restart, it must detect the requeue and resume from that checkpoint. Slurm sets `SLURM_RESTART_COUNT` on every restart. For complete examples, see [Handle Slurm signals for graceful shutdown](https://docs.coreweave.com/products/sunk/run_workloads/handle-slurm-signals.md) and [Checkpoint and restart Slurm jobs after a node failure](https://docs.coreweave.com/products/sunk/run_workloads/checkpoint-and-restart.md). Store checkpoints somewhere every node can reach, such as [CoreWeave AI Object Storage](https://docs.coreweave.com/products/storage/object-storage.md), because a requeued job can start on different nodes.

## Verify

After a Spot preemption, check what happened to the jobs that were running on the Slurm node whose Spot Node CoreWeave reclaimed. From a Slurm login node, replace `JOB_ID` with the job ID:

```bash theme={"system"}
sacct -D -j JOB_ID -o JobID,State,Restarts -X
```

```text title="Example output" theme={"system"}
JobID             State Restarts
------------ ---------- --------
34             REQUEUED        0
34              PENDING        1
```

A requeued job shows a `REQUEUED` entry followed by a new run with the same job ID and a higher `Restarts` count. Before the new run starts, `squeue` might show the job as pending with the reason `BeginTime`. A job that couldn't be requeued shows `CANCELLED`. A `NODE_FAIL` entry means the job was still running when the Kubernetes Node drained, for example because the warning window ended before SUNK requeued it, or because `onNotRequeueable: ignore` left a job that Slurm couldn't requeue running. If the job is eligible for requeue, a new run with the same job ID follows the `NODE_FAIL` entry. A job that Slurm can't requeue ends at `NODE_FAIL`.

To watch for preemption warnings from Kubernetes, see [Monitor preemption events](https://docs.coreweave.com/platform/capacity-plans/spot-node-pools.md#monitor-preemption-events).

## Related pages

* [Spot Node Pools](https://docs.coreweave.com/platform/capacity-plans/spot-node-pools.md): Spot availability, the preemption timeline, and usage monitoring.
* [Bind NodeSets to Node Pools for SUNK Standard](https://docs.coreweave.com/products/sunk/deploy_sunk/bind-nodesets-to-node-pools.md): matching Node Pool labels and taints in a NodeSet.
* [Syncer](https://docs.coreweave.com/products/sunk/discover_sunk/syncer.md): how SUNK keeps Slurm node state in sync with Kubernetes.
* [Handle Slurm signals for graceful shutdown](https://docs.coreweave.com/products/sunk/run_workloads/handle-slurm-signals.md): signal handlers and `KillWait`.
* [Checkpoint and restart Slurm jobs after a node failure](https://docs.coreweave.com/products/sunk/run_workloads/checkpoint-and-restart.md): resuming a requeued job from its last checkpoint.
* [SunkCluster reference](https://docs.coreweave.com/products/sunk/reference/sunkcluster-reference.md): the `computeClass` field.
