首先描述一下问题:
K8S 在启用多个POD 后,用户在操作管理界面时会出现获取不到 session 的问题
解决方法如下:
在Service 的 spec.sessionAffinity = ClientIP
可以将IP 接近的请求引用同一个POD
举例:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-tomcat
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/affinity-mode: "persistent"
nginx.ingress.kubernetes.io/session-cookie-name: "route"
spec:
tls:
- hosts:
- your.host.cn
secretName: https-secret
rules:
- host: your.host.cn
http:
paths:
- path:
backend:
serviceName: your service name
servicePort: 8280
---
apiVersion: v1
kind: Service
metadata:
name: tomcat
namespace: default
spec:
selector:
app: tomcat
release: canary
ports:
- name: http
targetPort: 8280
port: 8280
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 3600