Google Container Engine Load Balancer Issue With Session Affinity

12/6/2016

I have 3 Nginx pods running on the Google GKE Kubernetes cluster. I have exposed these pods to the external internet using the Kubernetes service with Load Balancer option (TCP Level 4). Sticky sessions are turned on using the SessionAffinity:ClientIP option.

When I access the external URL, the requests are forwarded to the same internal Nginx pod as expected from the SessionAffinity config. However if I keep the browser idle for about 3 minutes and then access the external URL again, the request goes to another Nginx pod. Why is this happening? Is there a SessionAffinity expiry or timeout that I can configure in GKE Load Balancer?

My Nginx Yaml,

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      replicas: 3
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80

My Service yaml for external load balancer,

    apiVersion: v1
    kind: Service
    metadata:
      name: live
    spec:
      ports:
        - name: name2
          port: 80
          targetPort: 80
          nodePort: 31080
      selector:
        app: nginx
      type: LoadBalancer
      sessionAffinity: ClientIP
-- Jayson Chacko
google-compute-engine
google-kubernetes-engine
kubernetes

0 Answers