group Block
Placement | job -> group |
The group
block defines a series of tasks that should be co-located on the
same Nomad client. Any task within a group will be placed on the same
client.
job "docs" {
group "example" {
# ...
}
}
group
Parameters
constraint
(Constraint: nil)
- This can be provided multiple times to define additional constraints.affinity
(Affinity: nil)
- This can be provided multiple times to define preferred placement criteria.spread
(Spread: nil)
- This can be provided multiple times to define criteria for spreading allocations across a node attribute or metadata. See the Nomad spread reference for more details.count
(int)
- Specifies the number of instances that should be running under for this group. This value must be non-negative. This defaults to themin
value specified in thescaling
block, if present; otherwise, this defaults to1
.consul
(Consul: nil)
- Specifies Consul configuration options specific to the group. These options will be applied to all tasks and services in the group unless a task has its ownconsul
block.ephemeral_disk
(EphemeralDisk: nil)
- Specifies the ephemeral disk requirements of the group. Ephemeral disks can be marked as sticky and support live data migrations.disconnect
(disconnect: nil)
- Specifies the disconnect strategy for the server and client for all tasks in this group in case of a network partition. The tasks can be left unconnected, stopped or replaced when the client disconnects. The policy for reconciliation in case the client regains connectivity is also specified here.meta
(Meta: nil)
- Specifies a key-value map that annotates with user-defined metadata.migrate
(Migrate: nil)
- Specifies the group strategy for migrating off of draining nodes. Only service jobs with a count greater than 1 support migrate blocks.network
(Network: <optional>)
- Specifies the network requirements and configuration, including static and dynamic port allocations, for the group.reschedule
(Reschedule: nil)
- Allows to specify a rescheduling strategy. Nomad will then attempt to schedule the task on another node if any of the group allocation statuses become "failed".restart
(Restart: nil)
- Specifies the restart policy for all tasks in this group. If omitted, a default policy exists for each job type, which can be found in the restart block documentation.service
(Service: nil)
- Specifies integrations with Nomad or Consul for service discovery. Nomad automatically registers each service when an allocation is started and de-registers them when the allocation is destroyed.shutdown_delay
(string: "0s")
- Specifies the duration to wait when stopping a group's tasks. The delay occurs between Consul or Nomad service deregistration and sending each task a shutdown signal. Ideally, services would fail health checks once they receive a shutdown signal. Alternatively,shutdown_delay
may be set to give in-flight requests time to complete before shutting down. A group levelshutdown_delay
will run regardless if there are any defined group services and only applies to these services. In addition, tasks may have their ownshutdown_delay
which waits between de-registering task services and stopping the task.task
(Task: <required>)
- Specifies one or more tasks to run within this group. This can be specified multiple times, to add a task as part of the group.update
(Update: nil)
- Specifies the task's update strategy. When omitted, a default update strategy is applied.vault
(Vault: nil)
- Specifies the set of Vault policies required by all tasks in this group. Overrides avault
block set at thejob
level.volume
(Volume: nil)
- Specifies the volumes that are required by tasks within the group.
group
Examples
The following examples only show the group
blocks. Remember that the
group
block is only valid in the placements listed above.
Specifying Count
This example specifies that 5 instances of the tasks within this group should be running:
group "example" {
count = 5
}
Tasks with Constraint
This example shows two abbreviated tasks with a constraint on the group. This will restrict the tasks to 64-bit operating systems.
group "example" {
constraint {
attribute = "${attr.cpu.arch}"
value = "amd64"
}
task "cache" {
# ...
}
task "server" {
# ...
}
}
Metadata
This example show arbitrary user-defined metadata on the group:
group "example" {
meta {
my-key = "my-value"
}
}
Network
This example shows network constraints as specified in the network block
which uses the bridge
networking mode, dynamically allocates two ports, and
statically allocates one port:
group "example" {
network {
mode = "bridge"
port "http" {}
port "https" {}
port "lb" {
static = "8889"
}
}
}
Service Discovery
This example creates a service in Consul. To read more about service discovery in Nomad, please see the Nomad service discovery documentation.
group "example" {
network {
port "api" {}
}
service {
name = "example"
port = "api"
tags = ["default"]
check {
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
task "api" { ... }
}