Sticky sessions (not in ingress)

Can I connect to specific pod of deployment without using a service (clusterIP)?

We have a deployment of nginx and an another deployment of backend. And we need to realize sticky sessions. For non-kubernetes deployments it will looks like

  upstream sticky-app {
        hash $cookie_key;
        server backend1:80;
        server backend2:80;
    }

But what should I do in kubernetes if backend1 and backend2 are pods of one deployment? I can access them by service that is resolved as single IP address, and as I know services don’t provide any mechanism for sticky sessions.

But service forwards the traffic randomly to one of the pods of the deployment. Or I don’t understand how to create a service that forwards traffic to the specific pod of the deployment.

You can’t choose which backend to send to unless you have some protocol-aware proxy. The link I gave you shows how to establish session affinity.

Well, I take that back. If you are in the same network as the pods, you can use a headless service which gives you a way to look up pods.

According to your link it is IP-based stickness. But it is not suitable for our case, as I understand. We have the scheme Ingress > Our Nginx > Backend.

Hi,

I have a question. What would you do if pod gets recreated with another ip? AFAIK the above nginx upstream configuration becomes outdated.
Is there really a need to have 2 reverse proxies before request reaches backend?