<p>I am trying to move my <strong>Springboot App with Elasticsearch</strong> to run on <strong>minikube</strong>.
But I would like to <strong>reuse</strong> the existing indexes which I created using <strong>local elastic search</strong> in the elastic search which runs on the Kubernetes. </p>

<p>I could see some documents about Persistent Volume but I could not find any info about <strong>reusing</strong> the existing index on the <strong>local directory</strong>.</p>

<p>Could someone please suggest some info about how to mount existing local directory which contains Elasticsearch indices on Kubernetes.</p>

<p>I am trying to run the Kubernetes cluster locally using minikube. This is my first try with Kubernetes. Therefore, I am not familiar with all aspects of it. I am trying to deploy a spring boot app which connects to Elasticsearch server.</p>

<p><strong>Elasticsearch Server - deployment.yaml</strong></p>

<pre class="lang-yaml prettyprint-override"><code>    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: elasticsearch
    spec:
      selector:
        matchLabels:
          run: elasticsearch
      replicas: 1
      template:
        metadata:
          labels:
            run: elasticsearch
        spec:
          containers:
            - image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
              name: elasticsearch
              imagePullPolicy: IfNotPresent
              env:
                - name: discovery.type
                  value: single-node
                - name: cluster.name
                  value: elasticsearch
              ports:
              - containerPort: 9300
                name: nodes
              - containerPort: 9200
                name: client

</code></pre>

nantitv
<p>Try to create a <code>StatefulSet</code> for the Elasticsearch which will work as Persistent Volume Claim (PVC)</p>

<p>Reference link for PVC: <a href="https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/</a></p>

<p>In the stateful set configuration, you need to mention <code>volumeMounts</code> like this:</p>

<pre><code>volumeMounts:
    - name: elasticsearch
      mountPath: /path/to/local_directory/local_indexes
</code></pre>

<p>This helps you to discover your older indexes (created locally) as well as the new ones too!</p>

<p>And to access these indexes as well, I would suggest creating <code>Service</code>, kind of a load balancer as well for the Elasticsearch. It will generate an external IP to access Elasticsearch configurations and indexes within the Kubernetes cluster. You can access by applying curl to the external IP generated.</p>
