rubykubernetessticky-sessionsession-affinity

Is there a way to provide custom value other than ClientIP for sessionAffinity in kubernetes?


First of all request goes to proxy service that i've implemented, service forwards request to pods randomly without using sessionAffinity. I want to send requests to same pod based on custom value that i've set in request parameters using post method. I've used sessionAffinity with my service yml.

Here's service yml with sessionAffinity:

apiVersion: v1
metadata:
  name: abcd-service
  namespace: ab-services
spec:
  ports:
  - name: http
    protocol: TCP
    port: ****
    targetPort: ****
    nodePort: *****
  selector:
    app: abcd-pod
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 600
  type: NodePort

Now problem is that when request are send by multiple client's from same ip address all requests are directed to single pod and not to other replicas, causing uneven load balancing. But I don't want requests to be forwarded randomly either. i want all request's from same client or different client to be forwarded based on custom value that i set in post request and not by clientIP considering clientIP resolves to source ip of each request.


Solution

  • As you can read here, it currently supports only ClientIP and None values.

    sessionAffinity string Supports "ClientIP" and "None". Used to maintain session affinity. Enable client IP based session affinity. Must be ClientIP or None. Defaults to None. More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies

    Unfortunatelly there are no other values allowed.