Hazelcast WAN Replication (Enterprise Only)

See something wrong? Edit this page.

This is a complete example presenting how to set two Hazelcast clusters (deployed in two different Kubernetes environments) with the WAN Replication in between them.

You can see the whole project here.

What You’ll Learn

In this guide you will create two Hazelcast clusters and will set up WAN Replication between them.

Introduction

This example focuses on the WAN Replication feature and assumes that you have some general knowledge about Hazelcast on Kubernetes. Here are some resources:

The example also assumes you have two running Kubernetes clusters, and the kubectl tool installed. For all the commands the indication (Receiver) means that kubectl uses the context of the receiver cluster, and the indication (Publisher) means that kubectl uses the context of the publisher cluster.

This Code Sample presents WAN Replication via LoadBalancer, which may result in the communication over only one of the target members. If you need higher performance, please check out External Smart Client and use such a configuration in the WAN Replication part.

1. Create Receiver Cluster

Hazelcast uses Kubernetes API for the member discovery and it therefore requires granting view permission to certain resources.

(Receiver) $ kubectl apply -f rbac.yaml

Then, create a secret with the Hazelcast Enterprise license key.

(Receiver) $ kubectl create secret generic hz-license-key --from-literal license=<hz-license-key>

Now, you can create the cluster with the following command.

(Receiver) $ kubectl apply -f receiver/statefulset.yaml

If you use Minikube, you need to execute minikube tunnel now in order to get LoadBalancer External IPs assigned.

Check that the cluster works correctly and note its External Load Balancer IP.

(Receiver) $ kubectl get all
NAME              READY   STATUS    RESTARTS   AGE
pod/hazelcast-0   1/1     Running   0          2m21s
pod/hazelcast-1   1/1     Running   0          2m11s
pod/hazelcast-2   1/1     Running   0          2m1s

NAME                 TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)          AGE
service/hazelcast    LoadBalancer   10.171.245.205   35.240.109.13   5701:31092/TCP   2m22s
service/kubernetes   ClusterIP      10.171.240.1     <none>          443/TCP          38m

NAME                         READY   AGE
statefulset.apps/hazelcast   3/3     2m22s

The external IP of the Hazelcast cluster is: 35.240.109.13.

2. Create Publisher Cluster

Again, we need to grant Kubernetes API resource permissions.

(Publisher) $ kubectl apply -f rbac.yaml

Then, update the WAN Replication configuration in publisher/hazelcast.yaml with the external IP of the Receiver cluster.

wan-replication:
  my-wan-replication:
    batch-publisher:
      my-publisher:
        cluster-name: dev
        target-endpoints: 35.240.109.13

Create ConfigMap with the Hazelcast configuration.

(Publisher) $ kubectl create configmap hazelcast-configuration --from-file=publisher/hazelcast.yaml

Again, we need to create a secret with the Hazelcast Enterprise license key.

(Receiver) $ kubectl create secret generic hz-license-key --from-literal license=<hz-license-key>

Finally, we can start the publisher Hazelcast cluster.

(Publisher) $ kubectl apply -f publisher/statefulset.yaml

Your two Hazelcast clusters are set up with the WAN Replication. Now, we can check if everything works correctly.

3. Verify WAN Replication

Insert data into the publisher Hazelcast cluster

(Publisher) $ kubectl exec -it hazelcast-0 -- /bin/bash
# java -cp lib/hazelcast-enterprise-all*.jar com.hazelcast.client.console.ClientConsoleApp
hazelcast[default] > ns rep
namespace: rep
hazelcast[rep] > m.put key value
null

Check that the data was replicated to the receiver Hazelcast cluster.

(Receiver) $ kubectl exec -it hazelcast-0 -- /bin/bash
# java -cp lib/hazelcast-enterprise-all*.jar com.hazelcast.client.console.ClientConsoleApp
hazelcast[default] > ns rep
hazelcast[rep] > m.get key
value

Summary

In this example we have seen how to use Hazelcast WAN replication features that can be used to keep multiple Hazelcast clusters in sync. WAN replication can be very useful for Multi-Cloud Deployments.