我在Google GKE Kubernetes集群上运行了3个Nginx pod . 我已使用带有Load Balancer选项(TCP Level 4)的Kubernetes服务将这些pod暴露给外部Internet . 使用SessionAffinity:ClientIP选项打开粘性会话 .
当我访问外部URL时,请求将转发到与SessionAffinity配置所期望的相同的内部Nginx pod . 但是,如果我让浏览器闲置大约3分钟,然后再次访问外部URL,请求将转到另一个Nginx pod . 为什么会这样?是否可以在GKE负载均衡器中配置SessionAffinity到期或超时?
我的Nginx Yaml,
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
我的服务yaml为外部负载 balancer 器,
apiVersion: v1
kind: Service
metadata:
name: live
spec:
ports:
- name: name2
port: 80
targetPort: 80
nodePort: 31080
selector:
app: nginx
type: LoadBalancer
sessionAffinity: ClientIP