consul
consul copied to clipboard
Configure service weight in consul
Hey,
Im trying to create service that includes weight , but eventually traffic is being spitted equally between my services . 2 servers are configured that way: passing: 10000 warning: 10000 1 server configured that way: passing: 1 warning: 1
the service I’m trying to use it is proxy server if that is important. My main goal is to route traffic mainly to the 2 first servers , and only small amount of traffic the the single one.
Hi @nivdahan18,
I have a few clarifying questions to help answer:
- Are the services in the Consul service mesh? Or are they outside of the service mesh (just using Consul for service discovery)?
- How are you defining the weights? And how are you addressing the services?
@jkirschner-hashicorp Weights can be specified in service registration using the weights field.
@nivdahan18, in order to use weights you must configure your applications to issue SRV queries to Consul's DNS server.
Per the docs at https://developer.hashicorp.com/consul/docs/discovery/dns#service-lookups, Consul does not consider the weight field when returning the DNS response.
…when DNS SRV response are sent, order is randomized, but weights are not taken into account.
The client application is responsible for parsing the weights associated with each record in the DNS response, and considering that information when deciding which address to connect to.
@jkirschner-hashicorp Answers bellow:
Are the services in the Consul service mesh? Or are they outside of the service mesh (just using Consul for service discovery)? – No service mesh How are you defining the weights? And how are you addressing the services? – Definition in service files under config-dir. We are addressing via DNS requests to consul servers.
If you're not using service mesh, follow @blake's guidance above. Your DNS query needs to be a SRV query for the weights to be returned. The DNS client is responsible for parsing the weights in the DNS SRV response and making a selection based on the weights. How are you issuing your DNS queries? And are you using SRV queries?