Geting the "pod name" value of a node on Hazelcast with Kubernetes autodiscovery

4/27/2020

In a Hazelcast based system, deployed on Kubernetes, using auto-discovery by service-label, I'm trying to get the Pod name that each node is deployed on. What I'm getting is indeed the pod name for the first node, but the service name for the second. For example, octane-deployment-blue-123c44bfb-xyzab (pod) and then 10-20-30-100.my-service.svc.cluster.local (service).

I'm fetching the values by

HazelcastInstance hazelcastInstance = getInstance();
Member localMember = hazelcastInstance.getCluster().getLocalMember();
String name = localMember.getSocketAddress().getAddress().getHostName();

It seems that the name is determined by the auto-discovery mechanism.

Any way of getting this value?

-- Ido Gal
autodiscovery
hazelcast
kubernetes
kubernetes-pod

1 Answer

4/27/2020

The simple answer of how to get Pod name is to skip all the Hazelcast part and just get Pod name from the env variable HOSTAME or with the use of Downward API like this:

env:
- name: MY_POD_NAME
  valueFrom:
    fieldRef:
      fieldPath: metadata.name

Saying that, its very weird that you receive service name by executing localMember.getSocketAddress().getAddress().getHostName(). Seems like a bug to me. You can raise an issue with the steps to reproduce here: https://github.com/hazelcast/hazelcast-kubernetes

-- RafaƂ Leszko
Source: StackOverflow