In the context of improving an API on Kubernetes, I am considering using a distributed hash table. My API always receives requests to an URL with this scheme:
www.myapi.com/id
Reading the documentation of Istio, it seems pretty direct and easy to get what I want. Indeed, Istio handles a load balancing scheme called ConsistentHashLB
. I such a scheme, the service destination is chosen according to a hash computed from several possible fields: HTTP header name, cookie, source IP, and an HTTP query parameter name.
In my case, I would need to compute the hash according to the id
associated with the request.
My question is double and conditional:
- Is it possible to read the
id
as an HTTP parameter name? - If affirmative, how should I specify the rule in the manifest? (the doc that I have read is not enough clear in this regard).
If negative, some idea? some trick? For example, I am considering adding the id as an HTTP header with `Nginx, but this would add an additional step.
2
Answers
As I mentioned in comments if I understand correctly you’re looking for a ConsistenHashLB path, there is documentation about that.
There is also github issue about that.
As for the http header question, you should be able to add it wither with:
There is Headers part on the istio documentation which shows how to add/remove headers with an example.
Below envoy filter add request header called customer-id with alice value to all request going though istio ingress gateway. I also commented code for response headers.
It should be possible with a webassembly : https://istio.io/latest/docs/concepts/wasm/
(But you will have some work to get it deployed)