<p>I am trying to create a multiple node cluster of elasticsearch. So which service should i use to create a cluster using kubernetes. I was able to do it within a node using headless service for the internal communication between es. But the same is not happening in the case of multiple node. Also which ip and port i have to mention in "discovery.zen.ping.unicast.hosts" of the master node in the elasticsearch.yml file in worker node.</p>

<p>deployment.yml file</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch-deployment
spec:
 selector:
 matchLabels:
   app: elasticsearch
 replicas: 2
 template:
   metadata:
     labels:
       app: elasticsearch
   spec:
     containers:
     - name: elasticsearch
       image: sandeepp163/elasticsearch:latest
       volumeMounts:
       - mountPath: /usr/share/elasticsearch/config/
         name: config
       - mountPath: /var/logs/elasticsearch/
         name: logs
     volumes:
     - name: config
       hostPath:
         path: "/etc/elasticsearch/"
     - name: logs
       hostPath:
         path: "/var/logs/elasticsearch"
</code></pre>

<p>internal-communication service config</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-cluster
spec:
  clusterIP: None
  selector:
    app: elasticsearch
  ports:
  - name: transport
    port: 9300
    targetPort: 9300
</code></pre>

<p>external service config</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: load-service
  labels:
    app: elasticsearch
spec:
  selector:
    app: elasticsearch
  type: NodePort
  ports:
  - nodePort: 31234
    port: 9200
    targetPort: 9200
</code></pre>

<p>The error im getting on the worker node.</p>

<pre><code>[2020-02-26T05:29:02,297][WARN ][o.e.d.z.ZenDiscovery     ] [worker] not enough master nodes discovered during pinging (found [[]], but needed [1]), pinging again
</code></pre>

<p>elasticsearch.yml file in worker</p>

<pre><code>cluster.name: xxx
node.name: worker
node.master: false
node.data: true
node.ingest: false
discovery.zen.ping.unicast.hosts: ["192.168.9.0"]
discovery.zen.minimum_master_nodes: 1
</code></pre>

<p>elasticsearch.yml in master</p>

<pre><code>cluster.name: xxx
node.name: master
node.master: true
node.data: false
node.ingest: false
</code></pre>

<p>Thanks</p>

sandeep P
<p>You could simply deploy Elasticsearch in a statefulset using HELM.</p>

<p><strong>1. Installing HELM:</strong></p>

<p>If you are using linux, type: <code>curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash</code></p>

<p>If not, see <a href="https://helm.sh/docs/intro/install/" rel="nofollow noreferrer">here</a> the installation process for your O.S.</p>

<p><strong>2.  Add the stable repository to Helm, and upgrade them:</strong></p>

<pre><code>helm repo add stable https://kubernetes-charts.storage.googleapis.com

helm repo update 
</code></pre>

<p><strong>3. Install Elasticsearch Helm chart</strong></p>

<p>Now you're able to install the <a href="https://github.com/helm/charts/tree/master/stable/elasticsearch" rel="nofollow noreferrer">Elasticsearch chart</a>, type:</p>

<pre><code>helm install stable/elasticsearch --generate-name
</code></pre>

<p>Wait for the installation, you could check using <code>kubectl get pods -l app=elasticsearch</code></p>

<p>To access you could use <code>proxy-port</code> on service name:</p>

<pre><code>ES_SVC=$(kubectl get svc -owide -l "app=elasticsearch" -o jsonpath="{.items[0].metadata.name}")

kubectl port-forward svc/$ES_SVC 9200:9200
</code></pre>

<p><strong>4.  Access the service:</strong></p>

<p>To access the service go to <a href="http://127.0.0.1:9200" rel="nofollow noreferrer">http://127.0.0.1:9200</a> from your browser.</p>

<p>Hope that helps.</p>
