Session Affinity
Session Affinity (or Sticky Session) is a technique that routes requests from the same user to the same pod.
Table of Contents
Session Affinity Overview
Consistent Hash Based
HTTP Header Based
yaml
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: reviews-session-affinity
spec:
host: reviews
trafficPolicy:
loadBalancer:
consistentHash:
httpHeaderName: "x-user-id"Cookie Based
yaml
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: reviews-cookie-affinity
spec:
host: reviews
trafficPolicy:
loadBalancer:
consistentHash:
httpCookie:
name: "session-id"
ttl: 0s # Cookie expiration time (0s = session cookie)Source IP Based
yaml
apiVersion: networking.istio.io/v1
kind: DestinationRule
metadata:
name: reviews-ip-affinity
spec:
host: reviews
trafficPolicy:
loadBalancer:
consistentHash:
useSourceIp: true