Can connect to elasticsearch pods using IP but not using pod name

10/16/2017

I have had success before specifying the hosts in my elasticsearch.yaml file by IP (hardcoding address:port) but I was told this is bad practice. I am trying to switch to using just the pod names for my ES cluster and now the pods aren't discovered/used as master. I have a elasticsearch.yml configMap for all 3 pods that I mount which has the following specs:

cluster.name: elasticsearch-logs
    node.name: ${HOSTNAME}
    node.master: true
    node.data: true
    network.host: _local_
    transport.tcp.port: 9300
    http.port: 9200 
    bootstrap.memory_lock: false
    xpack.security.enabled: false
    discovery.zen.minimum_master_nodes: 2
    discovery.zen.ping.unicast.hosts: ["es-0:9300", "es-1:9300", "es-2:9300"]

Along with this I have 2 services. One is a headless service and the other is a ClusterIP.

apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-svc
  labels:
    component: elasticsearch
    role: master
spec:
  selector:
    component: elasticsearch
    role: master
  ports:
  - name: transport
    port: 9300
    targetPort: 9300
  clusterIP: None


apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-discovery
  labels:
    component: elasticsearch
    role: master
spec:
  selector:
    component: elasticsearch
    role: master
  ports:
  - name: transport
    port: 9300
    protocol: TCP

And in the main StatefulSet file that creates the ES pods I have the port specs:

ports:
        - containerPort: 9200
          name: db
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP

I am trying to get all 3 pods to act as master (and data/client). When I look at one of pod logs (here es-0) after creating my services/statefulsets I see the following repeating errors:

[2017-10-16T15:31:29,078][WARN ][o.e.d.z.UnicastZenPing   ] [es-0] timed out after [5s] resolving host [es-1:9300]
[2017-10-16T15:31:29,079][WARN ][o.e.d.z.UnicastZenPing   ] [es-0] timed out after [5s] resolving host [es-2:9300]
[2017-10-16T15:31:32,080][WARN ][o.e.d.z.ZenDiscovery     ] [es-0] not enough master nodes discovered during pinging (found [[Candidate{node={es-0}{TUE-h8SNR6q7WbWUl2Pm-A}{XrTrBg3ATqSvlB3hTlezpg}{172.17.0.3}{172.17.0.3:9300}{ml.max_open_jobs=10, ml.enabled=true}, clusterStateVersion=-1}]], but needed [2]), pinging again
[2017-10-16T15:31:36,111][WARN ][o.e.d.z.UnicastZenPing   ] [es-0] failed to resolve host [es-1:9300]
java.net.UnknownHostException: es-1
    at java.net.InetAddress.getAllByName0(InetAddress.java:1280) ~[?:1.8.0_141]
    at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[?:1.8.0_141]
    at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[?:1.8.0_141]
    at org.elasticsearch.transport.TcpTransport.parse(TcpTransport.java:908) ~[elasticsearch-5.6.3.jar:5.6.3]
    at org.elasticsearch.transport.TcpTransport.addressesFromString(TcpTransport.java:863) ~[elasticsearch-5.6.3.jar:5.6.3]
    at org.elasticsearch.transport.TransportService.addressesFromString(TransportService.java:691) ~[elasticsearch-5.6.3.jar:5.6.3]
    at org.elasticsearch.discovery.zen.UnicastZenPing.lambda$null$0(UnicastZenPing.java:212) ~[elasticsearch-5.6.3.jar:5.6.3]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_141]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569) [elasticsearch-5.6.3.jar:5.6.3]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_141]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_141]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]
[2017-10-16T15:31:36,116][WARN ][o.e.d.z.UnicastZenPing   ] [es-0] failed to resolve host [es-2:9300]
java.net.UnknownHostException: es-2
    at java.net.InetAddress.getAllByName0(InetAddress.java:1280) ~[?:1.8.0_141]
    at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[?:1.8.0_141]
    at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[?:1.8.0_141]
    at org.elasticsearch.transport.TcpTransport.parse(TcpTransport.java:908) ~[elasticsearch-5.6.3.jar:5.6.3]
    at org.elasticsearch.transport.TcpTransport.addressesFromString(TcpTransport.java:863) ~[elasticsearch-5.6.3.jar:5.6.3]
    at org.elasticsearch.transport.TransportService.addressesFromString(TransportService.java:691) ~[elasticsearch-5.6.3.jar:5.6.3]
    at org.elasticsearch.discovery.zen.UnicastZenPing.lambda$null$0(UnicastZenPing.java:212) ~[elasticsearch-5.6.3.jar:5.6.3]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_141]
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569) [elasticsearch-5.6.3.jar:5.6.3]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_141]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_141]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]
[2017-10-16T15:31:39,120][WARN ][o.e.d.z.ZenDiscovery     ] [es-0] not enough master nodes discovered during pinging (found [[Candidate{node={es-0}{TUE-h8SNR6q7WbWUl2Pm-A}{XrTrBg3ATqSvlB3hTlezpg}{172.17.0.3}{172.17.0.3:9300}{ml.max_open_jobs=10, ml.enabled=true}, clusterStateVersion=-1}]], but needed [2]), pinging again

I am still able to reach elasticsearch through the browser at node-ip:node-port but I get 503 errors once I try and do /_cluster/state

I believe I have an error on the "networking" side with the ports but I'm not sure where exactly. What should I look into? Thanks!

StatefulSet

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: es
  labels:
    component: elasticsearch
    role: master
spec:
  serviceName: elasticsearch
  replicas: 3
  template:
    metadata:
      labels:
        component: elasticsearch
        role: master
      annotations:
       pod.alpha.kubernetes.io/init-containers: '[
        {
          "name": "init-sysctl",
          "image": "alpine:3.4",
          "imagePullPolicy": "IfNotPresent",
          "command": ["sysctl", "-w", "vm.max_map_count=262144"],
          "securityContext": {
            "privileged": true
           }
         }
       ]'
    spec:
      subdomain: elasticsearch-svc
      containers:
      - name: es-master
        securityContext:
          privileged: true
          capabilities:
            add:
              - IPC_LOCK
        image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
        imagePullPolicy: Always
        env:
        - name: "ES_JAVA_OPTS"
          value: "-Xms512m -Xmx512m"
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        volumeMounts:
        - name: storage
          mountPath: /data
        - name: config-volume
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml 
      volumes:
       - name: config-volume
         configMap:
          name: elasticsearch-config
  volumeClaimTemplates:
  - metadata:
      name: storage
      annotations:
        volume.beta.kubernetes.io/storage-class: standard
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 12Gi
-- appdap1
elasticsearch
kubernetes
minikube

1 Answer

10/16/2017

You need to connect with the full dns name:

es-0.elasticsearch-internal:9300
-- vascop
Source: StackOverflow