Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service registration for IPv6 docker addresses (Fixes #3785) #3790

Merged
merged 7 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 container’s 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) {
Expand Down Expand Up @@ -674,6 +675,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"readonly_rootfs": {
Type: fields.TypeBool,
},
"use_ipv6_address": {
Type: fields.TypeBool,
},
},
}

Expand Down Expand Up @@ -884,6 +888,9 @@ func (d *DockerDriver) detectIP(c *docker.Container) (string, bool) {
}

ip = net.IPAddress
if d.driverConfig.UseIPv6Address {
ip = net.GlobalIPv6Address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, it seems like we probably want to set auto = true here as well. While this complicates the already unfortunately confusing advertise = "auto" logic, I think it will do what users expect by automatically advertising the routable address for the container when it's possible to discover it.

Perhaps a better question is: It should be exceedingly rare that someone wants use_ipv6_address = true and advertise = "host", correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this has been addressed; leaving for historical purposes)

}
ipName = name

// Don't auto-advertise IPs for default networks (bridge on
Expand Down
5 changes: 5 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the container's IPv6 address (GlobalIPv6Address in Docker) when registering ...

`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.
Expand Down
70 changes: 70 additions & 0 deletions website/source/docs/job-specification/service.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set auto=true when use_ipv6_address=true this will no longer be necessary.


- `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.
Expand All @@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker -> Docker


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.


- - -

Expand Down