This Hazelcast Discovery Plugin provides the possibility to lookup IP addresses of other members by resolving those requests against a Kubernetes Service Discovery system.
This plugin supports two different options of resolving against the discovery registry.
-
A request to the REST API
-
DNS Lookup against a given DNS service name
Hazelcast, since 3.6, offers a, so called, Discovery SPI to integrate external discovery mechanisms into the system. For more information please rely on the official documentation, available here.
The available configuration properties are documented inside the Javadoc of this plugin: Configuration Properties
To configure the Kubernetes Service Discovery REST API, you first need to add the plugin to the applications classpath. If using maven, Gradle, sbt or similar tools, this is as easy as adding it to the build configuration.
<project>
<!-- maven standards -->
<dependencies>
<!-- application dependencies -->
<dependency>
<groupId>com.noctarius.discovery</groupId>
<artifactId>hazelcast-kubernetes-discovery</artifactId>
<version>${hazelcast-kubernetes-version}</version>
</dependency>
</dependencies>
</project>
This fragment will add the discovery plugin as well as necessary transitive dependencies into your application classpath. The second step is to configure the discovery plugin inside of your Hazelcast configuration. You have 3 options to configure the plugin:
-
Set a namespace, if no property is set the default namespace will be used:
<property name="namespace">MY-KUBERNETES-NAMESPACE</property>
-
Set a service name to scan all endpoints (pods) connected by a service (the query is combined with the namespace)
<property name="service-name">MY-SERVICE-NAME</property>
-
Set a service label and value. If no endpoints can be found by a given service name, the endpoints are queried by the service label name and value (inside the defined namespace). Multiple services and group can be defined by labels.
<property name="service-label-name">cluster01</property>
<property name="service-label-value">true</property>
<hazelcast>
<properties>
<!-- at the moment the discovery needs to be activated explicitly -->
<property name="hazelcast.rest.enabled">true</property>
<property name="hazelcast.discovery.enabled">true</property>
</properties>
<network>
<join>
<!-- deactivate normal discovery -->
<multicast enabled="false"/>
<tcp-ip enabled="false" />
<!-- activate the Kubernetes plugin -->
<discovery-strategies>
<discovery-strategy enabled="true"
class="com.noctarius.hazelcast.kubernetes.HazelcastKubernetesDiscoveryStrategy">
<properties>
<!-- configure discovery service API lookup -->
<property name="service-name">MY-SERVICE-NAME</property>
<property name="service-label-name">cluster01</property>
<property name="service-label-value">true</property>
<property name="namespace">MY-KUBERNETES-NAMESPACE</property>
</properties>
</discovery-strategy>
</discovery-strategies>
</join>
</network>
</hazelcast>
To configure the Kubernetes Hazelcast plugin to use DNS lookup, you first need to add the plugin to the applications classpath. If using maven, Gradle, sbt or similar tools, this is as easy as adding it to the build configuration.
<project>
<!-- maven standards -->
<dependencies>
<!-- application dependencies -->
<dependency>
<groupId>com.noctarius.discovery</groupId>
<artifactId>hazelcast-kubernetes-discovery</artifactId>
<version>${hazelcast-kubernetes-version}</version>
</dependency>
</dependencies>
</project>
This fragment will add the discovery plugin as well as necessary transitive dependencies into your application classpath. The second step is to configure the discovery plugin inside of your Hazelcast configuration.
The service-dns value here is defined as documented in the official Kubernetes DNS documentation.
<hazelcast>
<properties>
<!-- at the moment the discovery needs to be activated explicitly -->
<property name="hazelcast.discovery.enabled">true</property>
</properties>
<network>
<join>
<!-- deactivate normal discovery -->
<multicast enabled="false"/>
<tcp-ip enabled="false" />
<!-- activate the Kubernetes plugin -->
<discovery-strategies>
<discovery-strategy enabled="true"
class="com.noctarius.hazelcast.kubernetes.HazelcastKubernetesDiscoveryStrategy">
<properties>
<!-- configure discovery service API lookup -->
<property name="service-dns">MY-SERVICE-DNS-NAME</property>
</properties>
</discovery-strategy>
</discovery-strategies>
</join>
</network>
</hazelcast>