Spring / Hazelcast / Kubernetes:同时运行两个 pod 时节点无法启动

问题描述 投票:0回答:0

上下文

我正在尝试为在 Kubernetes 中运行的 Spring Boot API 设置 Hazelcast。该 API 在需要能够通信的两个 pod 中运行。

配置

我定义了以下 Hazelcast Java 配置:

<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast</artifactId>
  <version>5.2.2</version>
</dependency>
Config config = getCommonConfig();
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
joinConfig.getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getJoin().getKubernetesConfig().setEnabled(true)
        .setProperty("namespace", namespace)
        .setProperty("service-name", service);

问题描述

当只运行一个 pod 时,API 运行没有任何错误。

当我使用

kubectl scale deployment <deployment_name> --replicas=2
扩展我的应用程序时,第二个 pod 失败并显示以下堆栈跟踪:

WARN ConfigServletWebServerApplicationContext : Exception encountered during context initialization 
cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'hazelcastInstance' defined in class path resource [org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration$HazelcastServerConfigConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [com.hazelcast.core.HazelcastInstance]:
Factory method 'hazelcastInstance' threw exception; nested exception is java.lang.IllegalStateException: Node failed to start!

这个堆栈非常模糊,将

LOG_LEVEL
设置为
DEBUG
不会添加任何额外的日志。

当我有两个 pod 运行时,似乎在

@Bean
中定义的以下
HazelcastServerConfiguration
无法实例化,即使当我只有一个时它运行良好。

@Configuration(
    proxyBeanMethods = false
)
@ConditionalOnSingleCandidate(Config.class)
static class HazelcastServerConfigConfiguration {
    HazelcastServerConfigConfiguration() {
    }

    @Bean
    HazelcastInstance hazelcastInstance(Config config) {
        return HazelcastServerConfiguration.getHazelcastInstance(config);
    }
}

我试过了:

  • 使用
    hazelcast-kubernetes
    加上
    hazelcast
    ,发生了完全相同的问题。
  • LOG_LEVEL=DEBUG
    中运行以获取更多信息,但没有记录更多信息。
java spring kubernetes hazelcast
© www.soinside.com 2019 - 2024. All rights reserved.