Leader Election

Spring Cloud Kubernetes 领导选举机制使用 Kubernetes ConfigMap 实现 Spring Integration 的领导选举 API。

The Spring Cloud Kubernetes leader election mechanism implements the leader election API of Spring Integration using a Kubernetes ConfigMap.

多个应用程序实例争夺领导权,但领导权将仅授予其中一个。在授予领导权时,领导应用程序会收到具有领导 ContextOnGrantedEvent 应用程序事件。应用程序会定期尝试获取领导权,领导权会授予第一个调用者。领导者会保留其领导地位,直至其从集群中移除或放弃其领导权。在解除领导权时,前任领导者将收到 OnRevokedEvent 应用程序事件。在移除后,集群中的任何实例,包括前领导者,都可能成为新的领导者。

Multiple application instances compete for leadership, but leadership will only be granted to one. When granted leadership, a leader application receives an OnGrantedEvent application event with leadership Context. Applications periodically attempt to gain leadership, with leadership granted to the first caller. A leader will remain a leader until either it is removed from the cluster, or it yields its leadership. When leadership removal occurs, the previous leader receives OnRevokedEvent application event. After removal, any instances in the cluster may become the new leader, including the old leader.

要将它包括在你的项目中,请添加以下依赖项。Fabric8 Leader 实现

To include it in your project, add the following dependency. Fabric8 Leader Implementation

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-kubernetes-fabric8-leader</artifactId>
</dependency>

要指定用于领导选举的 configmap 的名称,请使用以下属性。

To specify the name of the configmap used for leader election use the following property.

spring.cloud.kubernetes.leader.config-map-name=leader