Elasticsearch高级Rest客户端,Kubernetes中的连接重置错误

时间:2019-10-14 07:52:44

标签: elasticsearch kubernetes rest-client

我正在使用单节点elasticsearch服务器和基于elasticsearch高级rest客户端的Java应用程序。两者都在Kubernetes集群中运行。

    @Bean(destroyMethod = "close")
    public RestHighLevelClient client(){
      RestHighLevelClient client = null;
      Logger.getLogger(getClass().getName()).info("Connecting to elasticsearch on host : " + host);
      client = new RestHighLevelClient(RestClient.builder(new HttpHost(host, port, "http")));
      return client;
    }

在服务闲置约10分钟之前,此方法工作正常。尝试查询Elasticsearch服务器时,Java服务会引发异常

java.io.IOException: Connection reset
    at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:948) ~[elasticsearch-rest-client-6.4.3.jar!/:7.2.0]
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227) ~[elasticsearch-rest-client-6.4.3.jar!/:7.2.0]
    at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1448) ~[elasticsearch-rest-high-level-client-7.2.0.jar!/:7.2.0]
    at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1418) ~[elasticsearch-rest-high-level-client-7.2.0.jar!/:7.2.0]
    at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1388) ~[elasticsearch-rest-high-level-client-7.2.0.jar!/:7.2.0]
    at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:930) ~[elasticsearch-rest-high-level-client-7.2.0.jar!/:7.2.0]

当我将请求三次发送到服务时,它将再次起作用。但是经过约10分钟的空闲时间后,服务将给出相同的例外。我有一个包含相同图像的docker-compose设置,但是没有这样的问题。

我的elasticsearch部署

apiVersion: v1
kind: Service
metadata:
  name: elasticsearch
spec:
  type: NodePort
  ports:
  - name: client
    port: 9200
    targetPort: 9200
  - name: nodes
    port: 9300
    targetPort: 9300
  selector:
    app: elasticsearch

---

apiVersion: apps/v1 
kind: StatefulSet
metadata:
  name: elasticsearch
spec:
  serviceName: elasticsearch
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      nodeSelector:
        beta.kubernetes.io/os: linux
      containers:
      - image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
        name: elasticsearch
        env:
        - name: cluster.name
          value: "docker-cluster"
        - name: 'ES_JAVA_OPTS'
          value: "-Xms512m -Xmx512m"
        - name: discovery.type
          value: "single-node"
        ports:
        - containerPort: 9200
        - containerPort: 9300
          name: mysql
        volumeMounts:
        - name: elasticsearch-persistent-storage
          mountPath: /usr/share/elasticsearch/data
      volumes:
      - name: elasticsearch-persistent-storage
        persistentVolumeClaim:
          claimName: elasticsearch-claim
      initContainers:
      - image: alpine:3.6
        command: ["/sbin/sysctl", "-w", "vm.max_map_count=262144"]
        name: elasticsearch-init
        securityContext:
          privileged: true

我的Java服务

    apiVersion: v1
kind: Service
metadata:
  name: search
spec:
  ports:
  - port: 9099
    targetPort: 9099
  selector:
    app: search

---

apiVersion: apps/v1 
kind: Deployment
metadata:
  name: search
spec:
  selector:
    matchLabels:
      app: search
  strategy:
    type: Recreate
  replicas: 1
  template:
    metadata:
      labels:
        app: search
    spec:
      nodeSelector:
        beta.kubernetes.io/os: linux
      containers:
      - image: search-service:0.0.1-SNAPSHOT
        name: search
        env:
        - name: ELASTIC_SEARCH_HOST
          value: elasticsearch
        - name: ELASTIC_SEARCH_PORT
          value: "9200"
        - name: ELASTIC_SEARCH_CLUSTER
          value: docker-cluster
        ports:
        - containerPort: 9099

0 个答案:

没有答案