在 Kubernetes 和 Spring Boot 微服务之间共享缓存

huangapple go评论68阅读模式
英文:

Share cache between microservices with Kubernetes and sping boot

问题

如何在Kubernetes中的复制微服务之间共享Spring缓存?
应该使用哪种技术?
解决方案应能支持高可用配置(例如:主/从;主动-主动灾难恢复等)。

如果可能,请同时提供Spring Boot配置。

英文:

How can I share the Spring cache between replicated microservices in kubernetes?
Which technology should I use?
The solution should be able to support an high available configuration (e.g.: master/slave; active-active DR and so on).

Please provide the spring boot configuration as well if possible.

答案1

得分: 3

Spring缓存具有缓存提供程序的概念 - 即在缓存实现背后支持缓存的技术。

默认情况下,缓存在内存中实现,因此不以任何方式复制。但是,您可以将其配置为与Redis一起运行,请参阅此教程以获取技术实现方面的详细信息

在这种情况下,同一个Redis实例应该可以从运行应用程序Pod的所有Kubernetes节点访问,从而实现分布式缓存。

根据您的实际需求,您还可以查看与EHcacheHazelcast的集成。我相信还存在其他选项,但这应该指引了方向。

英文:

Spring cache has a concept of cache providers - technologies standing behind the caching implementation.

By default the cache is implemented in-memory, so its not replicated in any manner. However you can configure it to run, say, with Redis. See this tutorial for technical implementation aspects

In this case the same redis instance should be accessible from all kubernetes nodes running the pod of your application and you will have distributed cache.

Depending on your actual needs you can also check the integration with EHcache or Hazelcast. I'm sure other options also exist but this should give a direction.

huangapple
  • 本文由 发表于 2020年9月3日 21:29:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63724718.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定