0

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.

deployment.yml file

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"

internal-communication service config

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

external service config

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

The error im getting on the worker node.

[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

elasticsearch.yml file in worker

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

elasticsearch.yml in master

cluster.name: xxx
node.name: master
node.master: true
node.data: false
node.ingest: false

Thanks

sandeep P
  • 67
  • 10
  • Can you add elasticsearch version, cluster version, the pod's log that is failing, etc? It will help us understanding your situation better. – Kamol Hasan Feb 26 '20 at 05:17
  • elasticsearch version: Version: 6.1.2, Build: 5b1fea5/2018-01-10T02:35:59.208Z, JVM: 1.8.0_201 logs :- [2020-02-26T05:28:19,634][WARN ][o.e.d.z.ZenDiscovery ] [worker] not enough master nodes discovered during pinging (found [[]], but needed [1]), pinging again – sandeep P Feb 26 '20 at 05:24
  • Can you add the yamls and the configuration files too? please add them in the question body. – Kamol Hasan Feb 26 '20 at 05:56
  • Can you please take a look now. – sandeep P Feb 26 '20 at 06:17
  • 1
    "not enough master nodes discovered during pinging" it looks like your master is down. Is your k8s self hosted? if you are interested to learn helm, then it is very easy to deploy elastic search clusters using helm charts. https://github.com/helm/charts/tree/master/incubator/elasticsearch – Shree Prakash Feb 26 '20 at 06:20

1 Answers1

1

You could simply deploy Elasticsearch in a statefulset using HELM.

1. Installing HELM:

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

If not, see here the installation process for your O.S.

2. Add the stable repository to Helm, and upgrade them:

helm repo add stable https://kubernetes-charts.storage.googleapis.com

helm repo update 

3. Install Elasticsearch Helm chart

Now you're able to install the Elasticsearch chart, type:

helm install stable/elasticsearch --generate-name

Wait for the installation, you could check using kubectl get pods -l app=elasticsearch

To access you could use proxy-port on service name:

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

kubectl port-forward svc/$ES_SVC 9200:9200

4. Access the service:

To access the service go to http://127.0.0.1:9200 from your browser.

Hope that helps.

Mr.KoopaKiller
  • 3,665
  • 10
  • 21
  • I am asking about multiple node clustering of elasticsearch. – sandeep P Feb 27 '20 at 04:47
  • Yes, i have this stack deploy in a cluster with 3 nodes, helm will manage the statefulset based on all your nodes. – Mr.KoopaKiller Feb 27 '20 at 06:20
  • 1
    okay thanks for the info i will try and let you know. Since i haven't started using helm. – sandeep P Feb 27 '20 at 06:32
  • Great, is pretty easy to use, if you try the steps above and see something weird please share and I will try to help you. – Mr.KoopaKiller Feb 27 '20 at 07:34
  • @Mr.KoopaKiller I wonder if you could help me out with a similar issue using HELM to [install elasticsearch with 3 nodes and production certificates](https://stackoverflow.com/q/70305348/11194047) – Peter Schwarz Dec 10 '21 at 13:40