<p>I had sticky session working in my dev environment with minibike with following configurations:</p>

<p>Ingress:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: gl-ingress
  annotations:
    nginx.ingress.kubernetes.io/affinity: cookie
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.global-static-ip-name: "projects/oceanic-isotope-199421/global/addresses/web-static-ip"
spec:
  backend:
    serviceName: gl-ui-service
    servicePort: 80
  rules:
  - http:
      paths:
      - path: /api/*
        backend:
          serviceName: gl-api-service
          servicePort: 8080
</code></pre>

<p>Service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: gl-api-service
  labels:
    app: gl-api
  annotations:
    ingress.kubernetes.io/affinity: 'cookie'
spec:
  type: NodePort
  ports:
  - port: 8080
    protocol: TCP
  selector:
    app: gl-api
</code></pre>

<p>Now that I have deployed my project to GKE sticky session no longer function. I believe the reason is that the Global Load Balancer configured in GKE does not have session affinity with the NGINX Ingress controller. Anyone have any luck wiring this up? Any help would be appreciated. I wanting to establish session affinity: Client Browser > Load Balancer > Ingress > Service. The actual session lives in the pods behind the service. Its an API Gateway (built with Zuul).</p>

<p>Session affinity is not available yet in the GCE/GKE Ingress controller.</p>

<p>In the meantime and as workaround, you can use the GCE API directly to create the HTTP load balancer. Note that you can't use Ingress at the same time in the same cluster.</p>

<ol>
<li>Use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport" rel="nofollow noreferrer">NodePort</a> for the Kubernetes Service. Set the value of the port in <code>spec.ports[*].nodePort</code>, otherwise a random one will be assigned</li>
<li><a href="https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typenodeport" rel="nofollow noreferrer">Disable kube-proxy SNAT load balancing</a></li>
<li>Create a Load Balancer from the GCE API, with <a href="https://cloud.google.com/compute/docs/load-balancing/http/backend-service#generated_cookie_affinity" rel="nofollow noreferrer">cookie session affinity</a> enabled.  As backend use the port from 1.</li>
</ol>
