Service registration for IPv6 docker addresses

This commit is contained in:
Wim 2018-01-24 14:39:50 +01:00
parent 31e212f467
commit 76f09db067
3 changed files with 82 additions and 0 deletions

View File

@ -217,6 +217,7 @@ type DockerDriverConfig struct {
CapAdd []string `mapstructure:"cap_add"` // Flags to pass directly to cap-add
CapDrop []string `mapstructure:"cap_drop"` // Flags to pass directly to cap-drop
ReadonlyRootfs bool `mapstructure:"readonly_rootfs"` // Mount the containers root filesystem as read only
UseIPv6Address bool `mapstructure:"use_ipv6_address"` // Flag to use the GlobalIPv6Address from the container as the detected IP
}
func sliceMergeUlimit(ulimitsRaw map[string]string) ([]docker.ULimit, error) {
@ -674,6 +675,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"readonly_rootfs": {
Type: fields.TypeBool,
},
"use_ipv6_address": {
Type: fields.TypeBool,
},
},
}
@ -884,6 +888,9 @@ func (d *DockerDriver) detectIP(c *docker.Container) (string, bool) {
}
ip = net.IPAddress
if d.driverConfig.UseIPv6Address {
ip = net.GlobalIPv6Address
}
ipName = name
// Don't auto-advertise IPs for default networks (bridge on

View File

@ -355,6 +355,11 @@ The `docker` driver supports the following configuration in the job spec. Only
]
}
```
* `use_ipv6_address` - (Optional) `true` or `false` (default). Use IPv6 Address
will use the containers IPv6 address (GlobalIPv6Address) when registering service checks and using
`address_mode = driver`.
See [service](/docs/job-specification/service.html) for details.
* `readonly_rootfs` - (Optional) `true` or `false` (default). Mount
the container's filesystem as read only.

View File

@ -104,6 +104,9 @@ does not automatically enable service discovery.
`address_mode="driver"`. Numeric ports may be used when in driver addressing
mode.
Docker and IPv6 containers: This setting is required if you want to register
the port of the (IPv6) service. See [below for examples.](#IPv6 docker containers)
- `tags` `(array<string>: [])` - Specifies the list of tags to associate with
this service. If this is not supplied, no tags will be assigned to the service
when it is registered.
@ -124,6 +127,10 @@ does not automatically enable service discovery.
addresses. Task will fail if driver network cannot be determined. Only
implemented for Docker and rkt.
Docker and IPv6 containers: If you want to register the IPv6 address
of the container you'll have to enable this and specify `use_ipv6_address`
in the docker driver configuration. See [below for examples.](#IPv6 docker containers)
- `host` - Use the host IP and port.
### `check` Parameters
@ -140,6 +147,10 @@ scripts.
[below for details.](#using-driver-address-mode) Unlike `port`, this setting
is *not* inherited from the `service`.
Docker and IPv6 containers: If you want to check the IPv6 address
of the container you'll have to enable this and specify `use_ipv6_address`
in the docker driver configuration. See [below for examples.](#IPv6 docker containers)
- `args` `(array<string>: [])` - Specifies additional arguments to the
`command`. This only applies to script-based health checks.
@ -186,6 +197,9 @@ scripts.
default. In Nomad 0.7.1 or later numeric ports may be used if
`address_mode="driver"` is set on the check.
Docker and IPv6 containers: Using a numeric port is required if you want to
check the port of (IPv6) service. See [below for examples.](#IPv6 docker containers)
- `protocol` `(string: "http")` - Specifies the protocol for the http-based
health checks. Valid options are `http` and `https`.
@ -463,6 +477,62 @@ In this case Nomad doesn't need to assign Redis any host ports. The `service`
and `check` stanzas can both specify the port number to advertise and check
directly since Nomad isn't managing any port assignments.
### IPv6 docker containers
The [Docker](/docs/drivers/docker.html#use_ipv6_address) driver support the
`use_ipv6_address` parameter in it's configuration.
Besides enabling this parameter you have to set `address_mode` parameter in
both `service` and `check` stanzas to `driver`.
You also have explicily specify the `port` that will be registered and checked.
For example
```hcl
job "example" {
datacenters = ["dc1"]
group "cache" {
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
use_ipv6_address = true
# No port map required!
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
network {
mbits = 10
}
}
service {
name = "ipv6-redis"
port = 6379
address_mode = "driver"
check {
name = "ipv6-redis-check"
type = "tcp"
interval = "10s"
timeout = "2s"
port = 6379
address_mode = "driver"
}
}
}
}
}
```
With IPv6 Nomad doesn't need to assign Redis any host ports. The `service`
and `check` stanzas can both specify the port number to advertise and check
directly since Nomad isn't managing any port assignments.
- - -