Elasticsearch provides a discovery module, called Zen Discovery, that allows different Elasticsearch nodes to find each other.
By default, Zen Discovery achieves this by pinging ports 9300 to 9305 on each loopback address (127.0.0.0/16), and tries to find Elasticsearch instances that respond to the ping. This default behavior provides auto-discovery for all Elasticsearch nodes running on the same machine.
However, if the nodes reside on different machines, they won't be available on the loopback addresses. Instead, they will have IP addresses that are private to their network. For Zen Discovery to work here, we must provide a seed list of hostnames and/or IP addresses that other Elasticsearch nodes are running on.
This list can be specified under the discovery.zen.ping.unicast.hosts property inside Elasticsearch's configuration file elasticsearch.yaml. But this is difficult because:
- The Pod IP address that these Elasticsearch nodes will be running on is very likely to change
- Every time the IP changes, we'd have to go inside each container and update elasticsearch.yaml
Fortunately, Elasticsearch allows us to specify this setting as an environment variable. Therefore, we can modify our deployment.yaml and add an env property under spec.template.spec.containers:
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.3.2
ports:
- containerPort: 9200
- containerPort: 9300
env:
- name: discovery.zen.ping.unicast.hosts
value: ""