-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Docker extra_hosts is ignored unless defined in the majority of the services within the group #12373
Comments
Hi @Dgotlieb 👋 Unfortunately since Have you tried the first workaround I mentioned in #11056 (comment)? In that particular case I thought it would be better to set at the sidecar config, but I didn't think about the scenario you have, with multiple sidecars. I think the A minimum job "my_job" {
# ...
group "my_group" {
# ...
task "extra-hosts" {
driver = "docker"
config {
image = "busybox:1"
extra_hosts = ["foo:127.0.0.1"]
}
lifecycle {
hook = "prestart"
}
}
# ...
}
} |
Hi @lgfa29, I can confirm that your workaround works (even) when using multiple services: job "my_job" {
type = "service"
datacenters = ["dc1"]
group "my_group" {
count = 1
network {
mode = "bridge"
port "service-a-port" {
to = 5555
}
port "service-b-port" {
to = 5556
}
port "service-c-port" {
to = 5557
}
port "service-d-port" {
to = 5558
}
port "service-e-port" {
to = 5559
}
}
service {
name = "service-a"
port = 5555
connect {
sidecar_service {}
}
}
service {
name = "service-b"
port = 5556
connect {
sidecar_service {}
}
}
service {
name = "service-c"
port = 5557
connect {
sidecar_service {}
}
}
service {
name = "service-d"
port = 5558
connect {
sidecar_service {}
}
}
service {
name = "service-e"
port = 5559
connect {
sidecar_service {}
}
}
task "my_task" {
driver = "docker"
config {
image = "nginx:alpine"
}
}
task "extra-hosts" {
driver = "docker"
config {
image = "busybox:1.33"
command = "/bin/sh"
args = ["local/extra_hosts.sh"]
}
template {
data = <<EOF
cat <<EOT >> /etc/hosts
foo:127.0.0.1
EOT
EOF
destination = "local/extra_hosts.sh"
}
lifecycle {
hook = "prestart"
}
}
}
} I just want to emphasize that in case there are template {
data = <<EOF
echo "foo 127.0.0.1" >> /etc/hosts
EOF
destination = "local/extra_hosts.sh"
} Would be nice to be able to use it in the future without the workaround 😅 but until then it's good enough 😄 Thanks! |
Nope, it means that there is quite a bit of extra work that needs to be done to get this fixed. Namely, we need to hoist all |
Nomad version
v1.2.6 (a6c6b47)
Operating system and Environment details
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic
Background
Since Nomad version 1.1.3
/etc/hosts
file was moved from the task level to the allocation level so that it can be shared between tasks of an allocation #10823According to the upgrade guides, when using
extra_hosts
with Consul Connect inbridge
network mode, theextra_hosts
values should be defined in the sidecar_task.config block instead of the task config level.Issue
When a group has more than one service, the
/etc/hosts
file is populated with theextra_hosts
only if the majority of the services contain theextra_hosts
inside thesidecar_task.config
block , otherwise the/etc/hosts
of the allocation is generated without theextra_hosts
.Expected Result
In case
sidecar_task
withextra_hosts
is defined in at least one of the group's services, theextra_hosts
should be populated in the/etc/hosts
file of the allocation.Workaround
Add the
extra_hosts
insidesidecar_task.config
block to the majority of the services usingconnect
within the group.Job file - before workaround.
Only 2 out of 5 services contain
extra_hosts
configured in thesidecar_task.config
:Job file - after workaround
3 out of 5 (majority) services contain
extra_hosts
configured in thesidecar_task.config
:Output: (as expected):
Side notes
Thanks!
The text was updated successfully, but these errors were encountered: