Catalog / Nomad Cheatsheet
Nomad Cheatsheet
A quick reference guide for HashiCorp Nomad, covering essential commands, concepts, and configurations for job scheduling and cluster management.
Nomad Basics
Core Concepts
Client: Executes tasks on behalf of Nomad. |
Driver: Responsible for executing tasks. Examples include |
Nomad CLI Commands
|
Submit a job to Nomad. |
|
Check the status of a job. |
|
Stop a running job. |
|
Show status of all the nodes. |
|
Show status of the allocation |
|
Displays the overall Nomad cluster status. |
Basic Job File Structure
|
Job Specification Details
Job Block
|
Defines the job. Must be unique within the datacenter. |
|
Specifies the datacenters where the job can run. |
|
Job type. Can be |
|
Specifies job priority. Higher number means higher priority. Default is 50. |
|
Controls the job update strategy. |
Group Block
|
Groups tasks together for scaling and placement. |
|
Number of task instances to run in this group. |
|
Defines restart policy for tasks in the group. |
|
Configures an ephemeral disk for tasks in the group. |
|
Defines constraints for task placement. |
Task Block
|
Defines a single unit of work to be executed. |
|
Specifies the task driver to use (e.g., docker, exec). |
|
Driver-specific configuration (e.g., Docker image, command). |
|
Specifies resource requirements (CPU, memory, network). |
|
Defines how the task should be registered as a service. |
|
Configures dynamic templates using Consul or Vault data. |
Advanced Features
Constraints
Constraints ensure that tasks are placed on suitable clients based on attributes. Example:
|
Common attributes: |
Update Strategy
|
Controls how jobs are updated (rolling updates, canary deployments). |
|
Maximum number of allocations that can be updated concurrently. |
|
Delay between updating allocations. |
|
Minimum time an allocation must be healthy before continuing. |
|
Automatically revert to the previous version if the update fails. |
Templates
Templates allow dynamic configuration based on Consul or Vault data. Example:
|
Networking and Service Discovery
Networking
|
Configures the network resources for a task. |
|
Defines a static port mapping. |
|
Defines a dynamic port mapping, assigned by Nomad. |
|
Configures network bandwidth in megabits per second. |
Service Discovery with Consul
Nomad integrates with Consul for service discovery. Example:
|
This registers the task with Consul, including health checks. |
Vault Integration
Nomad can retrieve secrets from Vault for secure configuration. Example:
|
Ensure that the Nomad client has appropriate Vault policies. |