taaefik,kubernetes session affinity、session会话保持

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了taaefik,kubernetes session affinity、session会话保持相关的知识,希望对你有一定的参考价值。

参考技术A kubernetes 上可以多实例(pod)高负载运行,但是如果应用如果没有做session 同步的话,就会导致 session 不一致。
kubernetes 有session 亲和性的功能(每个client每次访问,都会匹配到对应session的后端)

例子:

配置service 和 ingress
apiVersion: v1
kind: Service
metadata:
annotations:
traefik.backend.loadbalancer.sticky: "true"
spec:
sessionAffinity: ClientIP
sessionAffinityConfig:
clientIP:
timeoutSeconds: 10800

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
traefik.frontend.rule.type: PathPrefixStrip
traefik.ingress.kubernetes.io/affinity: "true"
traefik.ingress.kubernetes.io/load-balancer-method: drr
traefik.ingress.kubernetes.io/session-cookie-name: ttt

servlet使用sessio和spring mvc中的controller使用session

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

 

request.setCharacterEncoding("UTF-8");
response.setHeader("Content-type","text/html;charset=UTF-8");

HttpSession session = request.getSession(true);

session.setAttribute("rno",list.get(0));

}

 

 

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {

request.setCharacterEncoding("UTF-8");
response.setHeader("Content-type","text/html;charset=UTF-8");

HttpSession session = request.getSession(true);

String name = student.getSTUNAME();

session.setAttribute("name",name);

 

}

以上是关于taaefik,kubernetes session affinity、session会话保持的主要内容,如果未能解决你的问题,请参考以下文章

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Sessio

hadoop运行问题:INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.sessio

Kubernetes——Kubernetes基础+部署Kubernetes集群

Kubernetes——Kubernetes基础+部署Kubernetes集群

Kubernetes - Kubernetes部署Kubernetes Dashbaord

kubernetes学习01—kubernetes介绍