I’m looking for ideas and knowledge to understand options better to enable session affinity for my service.
Here are the details (simplified):
-
Everything is running in Kubenettes cluster (GKE).
-
Ingress class use
gce
-
Service-1 (Backend for the load balancer): gateway-service is just running a Nginx server for proxy (path based routing to different service).
-
Service-2 (real service): basically core API.
Both Service-1 and Service-2 have two pods in the Kube cluster. I need session affinity due to a AI conversation function. In Nginx conf, we use POD service name to route
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
# must append the prefix '/api' again because nginx trim the '/api' from the original path when match.
proxy_pass http://columns:8088/api;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
# some api call takes long
proxy_read_timeout 180;
}
Kube conf for both service-1:
# define nebula service from the open images
apiVersion: v1
kind: Service
metadata:
name: gateway
labels:
app: gateway-service
annotations:
cloud.google.com/backend-config: '{"default": "nginx-timeout"}'
spec:
type: NodePort
selector:
app: gateway-service
ports:
- port: 8080
name: http
targetPort: 8080
Kube conf for service2:
apiVersion: v1
kind: Service
metadata:
name: columns
spec:
type: NodePort
selector:
app: columns-service
ports:
- port: 8088
name: api
targetPort: 8088
- port: 3000
name: web
targetPort: 3000
- port: 8090
name: docs
targetPort: 8090
I know there are a lot of articles/discussions talking about setting session affinity on kube Ingress, I did that, but I think my problem is different, if I understand correctly, the Ingress session affinity is for how Load Balancer choose my gateway service (service 1), but I need extra thing in Service 1 (Nginx) to be able to create sticky session when it proxy_pass to the service-2 which is indicated at proxy_pass http://columns:8088/api;
Seems like the key to solve this problem is here to find a solution in Nginx which can build sticky session to http://columns:8088/api
, is it possible?
Exhausted my knowledge on this, I appreciate any help!