<p>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:</p>
<pre><code>www.myapi.com/id
</code></pre>
<p>Reading the documentation of Istio, it seems pretty direct and easy to get what I want. Indeed, Istio handles a load balancing scheme called <code>ConsistentHashLB</code>. 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.</p>
<p>In my case, I would need to compute the hash according to the <code>id</code> associated with the request.</p>
<p>My question is double and conditional:</p>
<ol>
<li>Is it possible to read the <code>id</code> as an HTTP parameter name?</li>
<li>If affirmative, how should I specify the rule in the manifest? (the doc that I have read is not enough clear in this regard).</li>
</ol>
<p>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.</p>

lrleon
<p>As I mentioned in comments if I understand correctly you're looking for a ConsistenHashLB path, there is <a href="https://istio.io/latest/docs/reference/config/networking/destination-rule/#LoadBalancerSettings-ConsistentHashLB-HTTPCookie" rel="nofollow noreferrer">documentation</a> about that.</p>
<p>There is also <a href="https://github.com/istio/istio/issues/11554" rel="nofollow noreferrer">github issue</a> about that.</p>
<hr />
<p>As for the http header question, you should be able to add it wither with:</p>
<ol>
<li><a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/" rel="nofollow noreferrer">Virtual Service</a></li>
</ol>
<p>There is <a href="https://istio.io/latest/docs/reference/config/networking/virtual-service/#Headers" rel="nofollow noreferrer">Headers</a> part on the istio documentation which shows how to add/remove headers with an example.</p>
<blockquote>
<p>Message headers can be manipulated when Envoy forwards requests to, or responses from, a destination service. Header manipulation rules can be specified for a specific route destination or for all destinations. The following VirtualService adds a test header with the value true to requests that are routed to any reviews service destination. It also removes the foo response header, but only from responses coming from the v1 subset (version) of the reviews service.</p>
</blockquote>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: reviews-route
spec:
  hosts:
  - reviews.prod.svc.cluster.local
  http:
  - headers:
      request:
        set:
          test: &quot;true&quot;
    route:
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v2
      weight: 25
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v1
      headers:
        response:
          remove:
          - foo
      weight: 75
</code></pre>
<ol start="2">
<li><a href="https://istio.io/latest/docs/reference/config/networking/envoy-filter/" rel="nofollow noreferrer">Envoy Filter</a></li>
</ol>
<blockquote>
<p>EnvoyFilter provides a mechanism to customize the Envoy configuration generated by Istio Pilot. Use EnvoyFilter to modify values for certain fields, add specific filters, or even add entirely new listeners, clusters, etc.</p>
</blockquote>
<p>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.</p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: lua-filter
  namespace: istio-system
spec:
  workloadSelector:
    labels:
      istio: ingressgateway
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: GATEWAY
      listener:
        filterChain:
          filter:
            name: &quot;envoy.http_connection_manager&quot;
            subFilter:
              name: &quot;envoy.router&quot;
    patch:
      operation: INSERT_BEFORE
      value:
       name: envoy.lua
       typed_config:
         &quot;@type&quot;: &quot;type.googleapis.com/envoy.config.filter.http.lua.v2.Lua&quot;
         inlineCode: |
            function envoy_on_request(request_handle)
                request_handle:headers():add(&quot;customer-id&quot;, &quot;alice&quot;)
            end
           # function envoy_on_response(response_handle)
           #     response_handle:headers():add(&quot;customer-id&quot;, &quot;alice&quot;)
           # end
</code></pre>
