<p>How can I deploy Elasticsearch on Kubernetes cluster? I need to use the Elasticsearch outside to my cluster. For that, which service that I should use? Can anyone post the deployment and service yaml files?</p>

ashique
<p>You can use the helm chart to deploy the elasticsearch if you want to run it in production.</p>
<p>Helm chart : <a href="https://github.com/elastic/helm-charts" rel="nofollow noreferrer">https://github.com/elastic/helm-charts</a></p>
<p>If you are just deploying for development and testing you can below YAML file :</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app : elasticsearch
    component: elasticsearch
    release: elasticsearch
  name: elasticsearch
spec:
  podManagementPolicy: Parallel
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app : elasticsearch
      component: elasticsearch
      release: elasticsearch
  serviceName: elasticsearch
  template:
    metadata:
      creationTimestamp: null
      labels:
        app : elasticsearch
        component: elasticsearch
        release: elasticsearch
    spec:
      containers:
      - env:
        - name: cluster.name
          value: &lt;SET THIS&gt;
        - name: discovery.type
          value: single-node
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        - name: bootstrap.memory_lock
          value: &quot;false&quot;
        image: elasticsearch:6.5.0
        imagePullPolicy: IfNotPresent
        name: elasticsearch
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        resources:
          limits:
            cpu: 250m
            memory: 1Gi
          requests:
            cpu: 150m
            memory: 512Mi
        securityContext:
          privileged: true
          runAsUser: 1000
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: elasticsearch-data
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - sh
        - -c
        - chown -R 1000:1000 /usr/share/elasticsearch/data
        - sysctl -w vm.max_map_count=262144
        - chmod 777 /usr/share/elasticsearch/data
        - chomod 777 /usr/share/elasticsearch/data/node
        - chmod g+rwx /usr/share/elasticsearch/data
        - chgrp 1000 /usr/share/elasticsearch/data
        image: busybox:1.29.2
        imagePullPolicy: IfNotPresent
        name: set-dir-owner
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: elasticsearch-data
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 10
  updateStrategy:
    type: OnDelete
  volumeClaimTemplates:
  - metadata:
      creationTimestamp: null
      name: elasticsearch-data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 10Gi
</code></pre>
<p>Ref Gist : <a href="https://gist.github.com/harsh4870/ccd6ef71eaac2f09d7e136307e3ecda6" rel="nofollow noreferrer">https://gist.github.com/harsh4870/ccd6ef71eaac2f09d7e136307e3ecda6</a></p>
<blockquote>
<p>which service that I should use</p>
</blockquote>
<p>You can expose the Elasticsearch service with type <strong>LoadBalancer</strong> and expose it to internet and use it.</p>
<p><strong>service.yaml</strong></p>
<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: eks-srv
spec:
  selector:
    app: elasticsearch
    component: elasticsearch
  ports:
    - name: db
      protocol: TCP
      port: 9200
      targetPort: 9200
    - name: monitoring
      protocol: TCP
      port: 9300
      targetPort: 9300
  type: LoadBalancer
</code></pre>
<p><strong>Note :</strong></p>
<p>you need to use the <strong>NodePort</strong> or <strong>LoadBalancer</strong> as service type with <strong>ClusterIp</strong> you wont be able to expose service unless you use some <strong>proxy</strong> setup or <strong>ingress</strong>.</p>
