I'm trying to build a 3 node (1 master + 2 nodes) Docker Swarm using Azure's Ubuntu image.
I've then tried to deploy an ElasticSearch 3 node cluster.
This is my YAML file:
version: '3.7'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.1
hostname: "{{.Node.Hostname}}"
environment:
- node.name={{.Node.Hostname}}
- cluster.name=rdcluster
- "ES_JAVA_OPTS=-Xms2g -Xmx2g"
- discovery.seed_hosts=elasticsearch
- cluster.initial_master_nodes=Docker01,Docker02,Docker03
- node.ml=false
- xpack.ml.enabled=false
- xpack.monitoring.enabled=false
- xpack.security.enabled=false
- xpack.watcher.enabled=false
- bootstrap.memory_lock=false
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
deploy:
mode: global
endpoint_mode: dnsrr
resources:
limits:
memory: 4G
networks:
- "myelasticnetwork"
nginx:
image: nginx:1.17.1-alpine
ports:
- 9200:9200
deploy:
mode: global
command: |
/bin/sh -c "echo '
user nobody nogroup;
worker_processes auto;
events {
worker_connections 1024;
}
http {
client_max_body_size 4g;
resolver 127.0.0.1 ipv6=off;
server {
listen *:9200;
location / {
proxy_set_header Connection keep-alive;
set $url http://elasticsearch:9200;
proxy_pass $url;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}' | tee /etc/nginx/nginx.conf && nginx -t && nginx -g 'daemon off;'"
volumes:
elasticsearch-data:
networks:
myelasticnetwork:
external:
name: "host"
Seems that Elastic is constantly restarting because of the heartbeats. I think that the problem is that in Azure we can't connect to "virtual" networks that aren't managed by Azure. In this case, my nodes host network is 10.0.0.0/20. Inspecting ElasticSearch network I get:
$ sudo docker network inspect elasticsearch_default
[
{
"Name": "elasticsearch_default",
"Id": "k05k4qy8z03gni1uaegk1rnaz",
"Created": "2021-01-31T19:35:38.82746565Z",
"Scope": "swarm",
**"Driver": "overlay",**
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
**"Subnet": "10.0.3.0/24",**
"Gateway": "10.0.3.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"8a397f15ed0dc79ca794dfea24283908bfb471b74c9122b6f68b59b424a7fb78": {
"Name": "elasticsearch_nginx.c9om15ttphfhecnlt2emrgrkv.afnl9d6p8ddwubvd3nrmn95fq",
"EndpointID": "04d59ae9f45425bbee98be271b16c79a329139202600c4745c4442a4f2c54fae",
"MacAddress": "02:42:0a:00:03:03",
"IPv4Address": "10.0.3.3/24",
"IPv6Address": ""
},
"lb-elasticsearch_default": {
"Name": "elasticsearch_default-endpoint",
"EndpointID": "b20c369d66835f3f330d0af2cbb40e2002046cbc1a11a58c76c2f61916978e69",
"MacAddress": "02:42:0a:00:03:06",
"IPv4Address": "10.0.3.6/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4099"
},
"Labels": {
"com.docker.stack.namespace": "elasticsearch"
},
"Peers": [
{
"Name": "5341d18c2eb1",
"IP": "10.0.0.7"
},
{
"Name": "c476ac76244e",
"IP": "10.0.0.16"
},
{
"Name": "2ebc9eb2cd10",
"IP": "10.0.0.8"
}
]
}
]
The bottom IP's (10.0.0.7, 10.0.0.8 and 10.0.0.16) matches with the nodes IP's. However the top IP's (10.0.3.X) are auto-generated and not by Azure.
Is there a way of saying that I want the 9200 port to be on the node IP? I've trying with the external.name = "host" but I didn't work.
Can anyone help me?
Thanks