Resource quotas
Enterprise Only
The functionality described here is available only in Nomad Enterprise with the Governance & Policy module. To explore Nomad Enterprise features, you can sign up for a free 30-day trial from here.
Nomad Enterprise provides support for resource quotas, which allow operators to restrict the aggregate resource usage of namespaces. Once a quota specification is attached to a namespace, the Nomad cluster will count all resource usage by jobs in that namespace toward the quota limits. If the resource is exhausted, allocations within the namespaces will be queued until resources become available—by other jobs finishing or the quota being expanded.
In this guide, you'll create a quota that limits resources in the global region. You will then assign the quota to a namespace where you will deploy a job. Finally, you'll learn how to secure the quota with ACLs.
Define and create a quota
You can manage resource quotas by using the nomad quota
subcommand. To
get started with creating a quota specification, run nomad quota init
which
produces an example quota specification.
The file spec.hcl
defines a limit for the global region. Additional limits may
be specified in order to limit other regions.
Resource limits
When specifying resource limits the following enforcement behaviors are defined:
limit < 0
: A limit less than zero disallows any access to the resource.limit == 0
: A limit of zero allows unlimited access to the resource.limit > 0
: A limit greater than zero enforces that the consumption is less than or equal to the given limit.
A quota specification is composed of one or more resource limits. Each limit applies to a particular Nomad region. Within the limit object, operators can specify the allowed CPU and memory usage.
Create the quota
To create the quota, run nomad quota apply
with the filename of your quota specification.
Check for success with nomad quota list
.
Attach a quota to a namespace
In order for a quota to be enforced, you have to attach the quota specification
to a namespace. This can be done using the nomad namespace apply
command. Add
the new quota specification to the default
namespace as follows:
View quota information
Now that you have attached a quota to a namespace, you can run a job in the default namespace.
Initialize the job.
Run the job in the default namespace.
Check the status.
Notice that the newly created job is accounted against the quota specification since it is being run in the namespace attached to the "default-quota" quota.
Now, add more instances of the job by changing count = 1
to count = 4
and
check to see if additional allocations were added.
The output indicates that Nomad created two more allocations but did not place the fourth allocation, which would have caused the quota to be oversubscribed on memory.
Secure quota with ACLs
Access to quotas can be restricted using ACLs. As an example, you could create an ACL policy that allows read-only access to quotas.
Proper ACLs are necessary to prevent users from bypassing quota enforcement by increasing or removing the quota specification.
Design for federated clusters
Nomad makes working with quotas in a federated cluster simple by replicating quota specifications from the authoritative Nomad region. This allows operators to interact with a single cluster but create quota specifications that apply to all Nomad clusters.
As an example, you can create a quota specification that applies to two regions:
Apply the specification.
Now that the specification is applied and attached to a namespace with jobs in each region,
use the nomad quota status
command to observe how the enforcement applies
across federated clusters.
Learn more about quotas
For specific details about working with quotas, consult the quota commands and HTTP API documentation.