How to deal with the communication between containers in a swarm cluster?

Asked

Viewed 43 times

0

I’m trying to climb a Cluster Elasticsearch on Docker Swarm, but I’m not succeeding in dealing with internal communication between us. The cluster knows and I can access the master on port 9200, however, when hitting the Elastic API it is possible to see that the cluster was not formed by issues related to communication between nodes.

Instruction to up the service:

docker stack deploy -c docker-stack.yml elastic

Docker-stack.yml

version: '3.7'

services:
  es-master:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
    hostname: "{{.Node.Hostname}}"
    environment:
      HOSTNAME: "{{.Node.Hostname}}"
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_PASSWORD: "password"
    configs:
      - source: elastic_config
        target: /usr/share/elasticsearch/config/elasticsearch.yml
    deploy:
      mode: global
      placement:
        constraints:
          - "node.role==manager"
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - elastic

  es-data:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
    hostname: "{{.Node.Hostname}}"
    environment:
      HOSTNAME: "{{.Node.Hostname}}"
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_PASSWORD: "password"
    configs:
      - source: elastic_config
        target: /usr/share/elasticsearch/config/elasticsearch.yml
    deploy:
      mode: global
      placement:
        constraints:
          - "node.role==worker"
    networks:
      - elastic

configs:
  elastic_config:
    file: ./elasticsearch.yml

networks:
  elastic:
    driver: overlay

Elasticsearch.yml

cluster.name: docker-cluster
network.host: 0.0.0.0

discovery.zen.minimum_master_nodes: 3

discovery.seed_hosts:
  - node1
  - node2
  - node3

cluster.initial_master_nodes:
  - node1
  - node2

My main point of difficulty is in understanding how communication takes place within the swarm cluster. How one container could communicate with another?

1 answer

0

Any service that is in this overlay network, sees its Lastic master by the name "es-master" can use es-master:9200 or any worker by "es-data", can use es-data:9200, whether or not you have exposed the port, as it did in master.

The port display, concerns who is outside the cluster, like you, with your browser, or applications that are outside the cluster and need to connect to it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.