volume Block
Placement | job -> group -> volume |
The volume
block allows the group to specify that it requires a
given volume from the cluster.
The key of the block is the name of the volume as it will be exposed to task configuration.
The Nomad server will ensure that the allocations are only scheduled
on hosts that have a set of volumes that meet the criteria specified
in the volume
blocks. These may be host volumes
configured on the client, or CSI volumes dynamically
mounted by CSI plugins.
The Nomad client will make the volumes available to tasks according to
the volume_mount block in the task
configuration.
volume
Parameters
type
(string: "")
- Specifies the type of a given volume. The valid volume types are"host"
and"csi"
.source
(string: <required>)
- The name of the volume to request. When usinghost_volume
's this should match the published name of the host volume. When usingcsi
volumes, this should match the ID of the registered volume.read_only
(bool: false)
- Specifies that the group only requires read only access to a volume and is used as the default value for thevolume_mount -> read_only
configuration. This value is also used for validatinghost_volume
ACLs and for scheduling when a matchinghost_volume
requiresread_only
usage.
The following fields are only valid for volumes with type = "csi"
:
access_mode
(string: <required>)
- Defines whether a volume should be available concurrently. Theaccess_mode
andattachment_mode
together must exactly match one of the volume'scapability
blocks. Can be one of"single-node-reader-only"
,"single-node-writer"
,"multi-node-reader-only"
,"multi-node-single-writer"
, or"multi-node-multi-writer"
. Most CSI plugins support only single-node modes. Consult the documentation of the storage provider and CSI plugin.attachment_mode
(string: <required>)
- The storage API that will be used by the volume. Theaccess_mode
andattachment_mode
together must exactly match one of the volume'scapability
blocks. Most storage providers will support"file-system"
, to mount volumes using the CSI filesystem API. Some storage providers will support"block-device"
, which will mount the volume with the CSI block device API within the container.per_alloc
(bool: false)
- Specifies that thesource
of the volume should have the suffix[n]
, wheren
is the allocation index. This allows mounting a unique volume per allocation, so long as the volume's source is named appropriately. For example, with the sourcemyvolume
andper_alloc = true
, the allocation namedmyjob.mygroup.mytask[0]
will require a volume IDmyvolume[0]
.The
per_alloc
field cannot be true for system jobs, sysbatch jobs, or jobs that use canaries.mount_options
- Options for mounting CSI volumes that have thefile-system
attachment mode. These options override themount_options
field from volume registration. Consult the documentation for your storage provider and CSI plugin as to whether these options are required or necessary.fs_type
: file system type (ex."ext4"
)mount_flags
: the flags passed tomount
(ex.["ro", "noatime"]
)
Volume Interpolation
Because volumes represent state, many workloads with multiple allocations will
want to mount specific volumes to specific tasks. The volume
block is used
to schedule workloads, so ${NOMAD_ALLOC_INDEX}
can't be used directly in the
volume.source
field. The following job specification demonstrates how to use
multiple volumes with multiple allocations, using the per_alloc
field. This
job specification also shows using HCL2 -variables interpolation to expose
information to the task's environment.
The job that results from this job specification has two task groups, each one named for each of the two volumes. Each allocation has its own volume.