How to create session-aware LoadBalancer via Ingress

7/14/2017

I have read all the documentation that I've found on the Google Cloud, Kubernetes and GitHub and I still cannot find the information on how to create Ingress resource that will work with sticky session. Yes there are some examples like this one but it does not guide me through the whole process. I'm not sure if I should create NodePort before using this configuration or not. I've described my current problem here and it seems to be similar to the one described here, but still, I was unable to find a clear answer/tutorial on how should I do it properly. What is the best practice here? There should be one, as this seem to be a problem that many web applications could have.

-- Seiya
google-cloud-networking
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

7/14/2017

This is less a question about Kubernetes and more a question about what kind of load balancer you have decided to use. Here is the Nginx documentation on how to implement session persistence.

If you were to use the Kubernetes Nginx ingress controller, the ingress definition is pretty simple. If you look at the source code for nginx.tmpl, you will see that the capability already exists. This yaml is probably all you would need.

Here is an example of how an nginx ingress controller can be set up. It even has examples of ingress rules, you could probably just add the above yaml to it. You'll notice that the nginx controller does use NodePort to expose its IP address.

-- Lindsay Landry
Source: StackOverflow