RabbitMQ 作为 Spring Kubernetes 中用于 Spring 启动应用程序的云总线

RabbitMQ as Spring Cloud Bus in Kubernetes for Spring Boot Applications

我开发了 Spring 引导应用程序。我已经设置了管理员和 RabbitMQ 以及 spring 云总线。当我刷新应用程序的端点时,它会刷新应用程序的属性。

谁能帮助我现在如何在 kubernetes 中设置 RabbitMQ?我做了一定程度的研究,在几篇文章中发现它需要部署为 "Statefulset" 而不是 "Deployment" https://notallaboutcode.blogspot.de/2017/09/rabbitmq-on-kubernetes-container.html。我不明白为什么需要这样做。此外,任何关于在 kubernetes 中部署 RabbitMQ 的有用 link 都会有所帮助。

这取决于您想要做什么以及您有哪些可用工具。我猜您当前的设置很像 http://www.baeldung.com/spring-cloud-bus 中描述的设置。将其移植到 kubernetes 的一种方法可能是尝试让您的设置首先使用 docker-compose,然后您可以将 docker-compose 移植到 kubernetes 部署描述符。

在 k8s 中部署 rabbitmq 的一种简单方法是使用 rabbitmq docker 映像设置部署。 https://github.com/Activiti/activiti-cloud-examples/blob/fe732096b5a19de0ad44879a399053f6ae02b095/kubernetes/kubectl/infrastructure.yml#L17 就是一个例子。 (请注意,该文件与 docker-compose 文件并没有根本不同,因此您可以从一个文件移植到另一个文件。)但这不会在 Pods 之外持久化数据,因此如果集群如果发生故障或 Pod/s 发生故障,那么您将丢失消息数据。坚持是短暂的。

因此,要获得非短暂的持久性,您可以像您指向的示例中那样使用 StatefulSet。另一个例子是 https://wesmorgan.svbtle.com/rabbitmq-cluster-on-kubernetes-with-statefulsets

如果您正在使用 helm(或可以使用 helm),那么您可以使用 rabbitmq helm chart, which uses a StatefulSet

但是,如果您需要总线的唯一原因是在发生 属性 更改时触发刷新,那么 Kubernetes 可以使用替代路径。我猜你需要热重载所以你可以看看使用 https://github.com/fabric8io/spring-cloud-kubernetes#propertysource-reload Or if you need the config to come from git specifically then you could look at http://fabric8.io/guide/develop/configuration.html (If you didn't need the hot reloads or git then you could consider versioning your configmaps and upgrading them with your application upgrades like in https://dzone.com/articles/configuring-java-apps-with-kubernetes-configmaps-a )

如果您的集群中安装了 helm

helm install stable/rabbitmq

这将在您的集群上安装 rabbitmqserver,以下命令用于获取密码和 erlang cookie,将 prodding-wombat-rabbitmq 替换为 w/e kubernetes 决定为广告连播命名。

kubectl get secret --namespace default prodding-wombat-rabbitmq -o jsonpath="{.data.rabbitmq-password}" | base64 --decode

kubectl get secret --namespace default prodding-wombat-rabbitmq -o jsonpath="{.data.rabbitmq-erlang-cookie}" | base64 --decode

要连接到 pod:

export POD_NAME=$(kubectl get pods --namespace default -l "app=prodding-wombat-rabbitmq" -o jsonpath="{.items[0].metadata.name}")

然后代理到本地主机,以便您可以在浏览器中连接

kubectl port-forward $POD_NAME 5672:5672 15672:15672