0

I'm trying to see how to configure Client-Server with my Spring Boot application using Hazelcast on Kubernete, since we want to have the capability of sharing the cache between different Spring Boot applications (I'm already able to setup the Embedded distributed cache with Kubernetes - which is not what we need). In case of Spring Boot single application(not on Kubernetes), its kind of easy where i will spin up a Server lets say with 'localhost' and also spin up the client connecting to localhost. Also i can have multiple instances(members) of Server which will form a Hazelcast Cluster.

However in case of Kubernetes, I know we need to have 2 different Spring Boot applications, one will act as a Server and others will be client accessing the cache, but want to know how the client would connect to the Server. Because in case of Spring we Autowire the HazelcastInstance, so how would i connect to the Server which is running in its own Kubernetes Pod ( and container).

3 Answers 3

1

Thanks Neil. As you indicated its the same way i currently configured in embedded caching on Kubernetes. I'am using the Service-Name and namespace to discover and connect to the Server members from HazelcastClient instance.

This is from Client Spring Boot application's HazelcastConfiguration:

@Bean
public HazelcastInstance hazelcastInstance() {
    final ClientConfig config = new ClientConfig();
    config.setClusterName("cluster-name");
    if (enableOnK8s) {
        config.getNetworkConfig().getKubernetesConfig().setEnabled(true)
            .setProperty("namespace", namespaceValue)
            .setProperty("service-name", serviceName);
    }
        return HazelcastClient.newHazelcastClient(config);
}

And on Hazelcast Server Spring Boot application, configuration stays same as Embedded Hazelcast configuration.

0

There are a few deployment guides for Kubernetes here, and worked examples here & here.

If your server pods are joining, then you pretty much have it. A client uses the same discovery mechanism.

Add the hazelcast-kubernetes plugin to the client's pod, and set the configuration properties with the same values as you use on the server for namespace, dns, etc.

0
0

Hi Please find the Client configuration I have used to connect with hazelcast deployed in k8.

@Bean
public ClientConfig hazelcastClientConfig() {
    ClientConfig config = new ClientConfig();
    ClientNetworkConfig networkConfig = config.getNetworkConfig();
    networkConfig.setSmartRouting(false);
    networkConfig.addAddress("<externalIp>:<port>"); // Replace with the actual IP address and port of your Hazelcast server
    return config;
}
@Bean
public HazelcastInstance hazelcastInstance() {
    return HazelcastClient.newHazelcastClient(hazelcastClientConfig());
}

And I used the following dependency as well

<dependency>
  <groupId>com.hazelcast</groupId>
  <artifactId>hazelcast-client</artifactId>
  <version>3.12.13</version> 
</dependency>

Not the answer you're looking for? Browse other questions tagged or ask your own question.