4

I'm trying to achieve stickiness on kubernetes cluster but I am redirected to a different pod every time I access the load balancer. I have session affinity set to 'ClientIP' and also tried with 'Generated Cookie'.

I have the following backend Service set up:

apiVersion: v1
kind: Service
metadata:
  annotations:
    beta.cloud.google.com/backend-config: '{"ports": {"80":"test-backendconfig"}}'
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{"beta.cloud.google.com/backend-config":"{\"ports\": {\"80\":\"test-backendconfig\"}}"},"labels":{"app":"test","tier":"frontend"},"name":"test","namespace":"default"},"spec":{"ports":[{"name":"backend-port","port":80,"targetPort":5000}],"selector":{"app":"test","tier":"frontend"},"sessionAffinity":"ClientIP","type":"NodePort"}}
  creationTimestamp: 2018-12-31T18:01:26Z
  labels:
    app: test
    tier: frontend
  name: test
  namespace: default
  resourceVersion: "..."
  selfLink: /api/v1/namespaces/default/services/test
  uid: ...
spec:
  clusterIP: 10.**.***.***
  externalTrafficPolicy: Cluster
  ports:
  - name: backend-port
    nodePort: 32385
    port: 80
    protocol: TCP
    targetPort: 5000
  selector:
    app: test
    tier: frontend
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 10800
  type: NodePort
status:
  loadBalancer: {}

1 Answer 1

3

Seems like the problem here is that the Client IP that the service sees is the Load Balancer IP (this assumes you are using an ingress with your Node Port service). This article discuses this issue a bit more and provides a workaround.

Alternatively, you can use Network Endpoint Groups which will essentially allow the front end Load Balancer to send traffic directly to the container backends which should improve session affinity. You still can't include the session affinity definition into your ingress config for GKE, but you can edit the L7LB resource once it has been created to enable session affinity

I would also suggest creating a feature request with Google to add annotations to the ingress resource to configure LB session affinity to have this functionality built into GKE (it's not usually recommended to modify GKE resources outside of k8s once they have been created)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .