-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Added cluster/leader endpoint #3009
Conversation
ebad7d0
to
a42d6e6
Compare
Hey @aantono, could you explain why you need to access to the API only on the leader ? |
If you add all the instances to an ELB for their api port, you get fluctuations in the data, specifically the health/stats, because each request gets randomly sent to some instance. Having only 1 instance (the leader) of the cluster be there would make things more consistent. All of api requests would always be routed to the leader in that setup. If one wants to have all the instances randomly routed, they can use |
@aantono so you are using the cluster in fail over mode right ? |
Yep. Though we only use it in that mode for access to API/Dashboard endpoint, but it can be used in that mode for traffic routing as well, depending on which ports the ELB is proxying. |
server/server.go
Outdated
@@ -724,6 +724,10 @@ func (s *Server) addInternalRoutes(entryPointName string, router *mux.Router) { | |||
if s.globalConfiguration.API != nil && s.globalConfiguration.API.EntryPoint == entryPointName { | |||
s.globalConfiguration.API.AddRoutes(router) | |||
} | |||
|
|||
if s.leadership != nil { |
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.
You can't put this route on all entrypoints.
This route must be activated only on the entrypoint where we activate --api
. So you need to put it in the API if
.
Moreover, I think the endpoint should be /api/cluster/leader, WDYT?
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
Thanks for your contribution @aantono 👏
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 introduces a
/cluster/leader
endpoint, which will return200-OK
or429-Too-Many-Requests
status, depending on if the particular node is a leader or not. The corresponding json payload will also be returned with{"leader":"true"}
in case the node is a leader and{"leader":"false"}
if it is not.Motivation
This will enable creating various Load Balancers on top of a Traefik cluster, which will only route API requests to the current leader, instead of randomly to any instance in the cluster. The return of
429
status code will make most load balancers (like Netscalar or ELB, etc) to keep the instances in the pool, but "temporarily" not send any requests to them.