-
Notifications
You must be signed in to change notification settings - Fork 753
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
fix: use hostIP also on entrypoint and healthChecks when set #992
Conversation
Thanks for your interest in Traefik and this PR @Zebradil ! In PR description:
When reading documentation, it's not very clear.
On host:
When it's really super specific, the encouraged approach is to use Would you please detail how they are different things and should not be mixed ? |
Since there is no answer from @Zebradil, I close this PR. |
Sorry, I haven't had enough time to perform a couple of experiments that are required to provide more information. If you don't mind, I'll ping you in this PR when it's ready. |
Sure, I re-open the PR then. |
Sorry for the long delay, I have finally double-checked the case. So for me, If I set Here is an example connections via an external interface ( $ curl -fsS localhost:9101/metrics | head -n3
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.3503e-05
$ curl -fsS 192.168.0.74:9101/metrics | head -n3
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.3503e-05 The related container configuration: containers:
- args:
- --entrypoints.metrics.address=:9101/tcp
- ...
image: docker.io/traefik:v2.11.0
ports:
- containerPort: 9101
hostPort: 9101
name: metrics
protocol: TCP
- ...
dnsPolicy: ClusterFirstWithHostNet
hostNetwork: true
... Now, if I set hostIP using the following port configuration: ports:
- containerPort: 9101
hostIP: localhost
hostPort: 9101
name: metrics
protocol: TCP I still can connect to the metrics port as before, even though I expect it to be unavailable on the external interface: $ curl -fsS localhost:9101/metrics | head -n3
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.7295e-05
curl: (23) Failure writing output to destination
$ curl -fsS 192.168.0.74:9101/metrics | head -n3
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.7295e-05 But if I revert hostIP and set localhost in the arguments, traefik correctly exposes the port only on the loopback interface: - args:
- --entrypoints.metrics.address=localhost:9101/tcp
- ... $ curl -fsS localhost:9101/metrics | head -n3
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 3.2208e-05
$ curl -fsS 192.168.0.74:9101/metrics | head -n3
curl: (7) Failed to connect to 192.168.0.74 port 9101 after 3 ms: Couldn't connect to server I wasn't able to find a proper explanation of how My notes in the original comment are related to the overall ergonomics of this change. I see room for improvement by adding extra logic in addition to the existing change. Maybe it is better to rename |
@mloiseleur I removed the dedicated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my suggestions
Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>
Good points, I applied all of them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What does this PR do?
This PR adds a new value
ports.*.host
that allows defining the entrypoint host to listen to.Motivation
This is useful when
hostNetwork
is enabled, ashostIP
doesn't make any effect in this case.Without setting an entrypoint's host, service entrypoints like
metrics
are exposed to the world.More
make test
and all the tests passedNotes
This proposal needs to be considered more carefully. Here are some data points to keep in mind:
host
(e.g. using127.0.0.1
instead of default0.0.0.0
), except when usinghostNetwork
.ports.traefik.host
from the default value can break probes because they use the Pod IP by default. To make them work,httpGet.host
has to be set to the same value asports.traefik.host
. However, at the moment, this helm chart doesn't provide a way to set probes'host
via values.hostIP
instead of a dedicatedhost
, but then I realized those are two different things and should not be mixed.Maybe it makes sense to add some logic to link
hostNetwork
andports.*.host
fields 🤔