Search code examples
javakuberneteshazelcast

Each pod has its own Hazelcast iList


I configured in the hazelcast.xml file of my microservice a list like following

<list name="listA">
    <statistics-enabled>false</statistics-enabled>
    <backup-copy>1</backup-copy>
<list>

When I deployed the microservice on k8s cluster with replicas=2, I was expecting that the values of listA are shared to both pods, meaning that when pod-0 add an entry to listA that entry will be visible for pod-1. But I found that each pod has its own separate instance and I am not sure why, any help/suggestion is appreciated.

Or should I use Hazelcast's IMap instead?


Solution

  • Have your pods formed a cluster ?

    Do you get a message in the logs such as:

    Members {size:2, ver:2} [
        Member [12.34.56.001]:5701 - 7ee6659e-620c-4db6-b348-8769000c2b0a
        Member [12.34.56.002]:5701 - 41238cc4-ef9a-4d50-94a7-a8fab67f43de this
    ]
    

    If you see size:2 it's a cluster of two pods. If it's a cluster of two pods, your listA should be accessible from both.

    If you have replicas==2 then you'll get two pods, but if they can't find each other they'll form two clusters of one pod rather than one cluster of two pods.

    You need to check the discovery section for Kubernetes. See here. The easiest way is to turn off multicast, turn on Kubernetes, use the default namespace and a service name. Once you have that running you can expand to different namespaces, roles, operators, helm charts, etc.

    This guide might help also.