Service proxy with affinity based on URL Service proxy with affinity based on URL kubernetes kubernetes

Service proxy with affinity based on URL


As you have already mentioned, IPVS proxy algorithm defines source and destination IP addresses in order to generate a unique hash key for load balancing. However, it operates in L4 transport layer of intercepting network traffic for TCP or UDP services. Therefore it might be difficult to interact with HTTP request and make a route decision based on URL path.

Envoy proxy represents consistent hashing via HTTP header values, specified inside HTTP router filter along with Ring hash load balancing policy. Therefore, you can specify the appropriate header name in Hash policy that can be used to obtain the hash key for load balancing.

hash_policy:  header:    header_name: "x-url"

Alternatively, you can consider to use Istio as an intermediate proxy which uses extended version of Envoy. Kubernetes services are involved into the service mesh by deploying a special sidecar proxy throughout your environment that intercepts all network communication between microservices. Istio can be also used for Hash consistent load balancing with session affinity based on HTTP headers via DestinationRule resource.

apiVersion: networking.istio.io/v1alpha3kind: DestinationRulemetadata:  name: examplespec:  host: my-service.default.svc.cluster.local  trafficPolicy:    loadBalancer:      consistentHash:        httpHeaderName: x-url