简体   繁体   English

SpringBoot控制器跨Docker Pod重定向

[英]SpringBoot controler redirect across docker poods

We have a SpringBoot Web app docker container deployed in Kubernetes with 3 replicas. 我们在Kubernetes中部署了一个带有3个副本的SpringBoot Web应用程序Docker容器。 when the controller redirects to a different url within the same controller, we pass an object via the flashAttributes. 当控制器重定向到同一控制器内的其他url时,我们通过flashAttributes传递一个对象。 When we run 1 pod, everything works. 当我们运行1个pod时,一切正常。 But when I scale to 3 pods, the object comes with all internal attributes set to Null. 但是,当我缩放到3个窗格时,该对象将所有内部属性设置为Null。 Has anyone come across the issue ? 有没有人遇到这个问题? If so prescribe a solution ? 如果可以,请提供解决方案?

Thanks, 谢谢,

SR SR

Kubernetes can send multiple requests from a session to different pod within a deployment. Kubernetes可以将一个会话中的多个请求发送到部署中的其他Pod。 That's why the data is lost because the data might in memory for one pod but another pod will not have that data at all. 这就是为什么丢失数据的原因,因为数据可能在一个Pod的内存中,但另一个Pod根本没有该数据。

To avoid this - you can either maintain the session cache in an external store like Redis or use sticky sessions so that for given session requests are sent to the same pod. 为了避免这种情况,您可以在Redis这样的外部存储中维护会话缓存,也可以使用粘性会话,以便将给定的会话请求发送到同一Pod。

Some pointers to the solution 一些解决方案的指针

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM