在minikube集群上运行的Elasticsearch服务无法从集群内部访问

时间:2019-06-10 16:49:05

标签: elasticsearch minikube kompose

我正在使用 kompose 部署此docker-compose.yaml

version: '3'
services:
  webapp:
    build:
      context: ../../../
      dockerfile: config/docker/dev/Dockerfile-dev
    container_name: myWebApp-dev
    command: ["/bin/sh", "-ec","sleep 1000"]
    image: 'localhost:5002/webapp:1'
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
      - ELASTICSEARCH_HOST=elasticsearch
    labels:
      kompose.image-pull-policy: 'IfNotPresent'
      kompose.service.type: nodeport
    ports:
      - "4000:4000"
      - "3000:3000"
    depends_on:
      - elasticsearch
    links:
      - elasticsearch

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: elasticsearch
    command: ["/bin/sh", "-ec","sleep 1000"]
    environment:
      - node.name=elasticsearch
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: es02
    command: ["/bin/sh", "-ec","sleep 1000"]
    environment:
      - node.name=es02
      - discovery.seed_hosts=elasticsearch
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata02:/usr/share/elasticsearch/data

到minikube。 elasticsearch pod和服务正在运行。但是,Webapp无法访问elasticsearch集群,因为从webapp pod中进行卷曲时,我收到拒绝连接错误:> curl:(7)无法连接到10.108.5.31端口9200:连接被拒绝。有谁知道这个问题的原因是什么以及如何解决它?

1 个答案:

答案 0 :(得分:0)

elasticsearch部分中,您有一个sleep的shell命令。而且,此后再也不会启动任何Elasticsearch实例。

command: ["/bin/sh", "-ec","sleep 1000"]

因此,看起来容器内没有运行Elasticsearch,这就是connection refused发生的原因。

要修复:

摆脱command:elasticsearch中的es02,将使用默认的command

注意:

现在,当elasticsearch启动时,在kubernetes中使用此组合yaml将面临两个错误(如下所述)。这些与这篇文章无关,但我会尽力为您提供指导。

ERROR: [2] bootstrap checks failed
[1]: memory locking requested for elasticsearch process but memory is not locked
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

在这里

  1. 您需要update host systemvm.max_map_count。由minikube ssh执行到minikube virtualbox中,然后运行sudo -s sysctl -w vm.max_map_count=262144更改主机内核的map_count。之所以会起作用,是因为 docker / container不提供内核级隔离

对于minikube,

minikube ssh 'sudo -s sysctl -w vm.max_map_count=262144'
  1. ulimit在kompose中不可用。 See issue here。因此,要么必须摆脱bootstrap.memory_lock=true部分中的environment:要么,或者您可能需要更新docker映像。这个问题已经在stackoverflow here中提出过。

所以改进的kompose yaml(在minikube上效果很好):

version: '3'
services:
  webapp:
    build:
      context: ../../../
      dockerfile: config/docker/dev/Dockerfile-dev
    container_name: myWebApp-dev
    command: ["/bin/sh", "-ec","sleep 1000"]
    image: 'localhost:5002/webapp:1'
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
      - ELASTICSEARCH_HOST=elasticsearch
    labels:
      kompose.image-pull-policy: 'IfNotPresent'
      kompose.service.type: nodeport
    ports:
      - "4000:4000"
      - "3000:3000"
    depends_on:
      - elasticsearch
    links:
      - elasticsearch

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=elasticsearch
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - esdata02:/usr/share/elasticsearch/data

但是,我建议遵循elasticsearch official doc,而不是使用compose在kubernetes中安装elasticsearch。