Mount local directory having Elasticsearch indices to Minikube

5/17/2020

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

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

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

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.

Elasticsearch Server - deployment.yaml

    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
-- nantitv
elasticsearch
kubernetes
minikube

1 Answer

5/18/2020

Try to create a StatefulSet for the Elasticsearch which will work as Persistent Volume Claim (PVC)

Reference link for PVC: https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/

In the stateful set configuration, you need to mention volumeMounts like this:

volumeMounts:
    - name: elasticsearch
      mountPath: /path/to/local_directory/local_indexes

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

And to access these indexes as well, I would suggest creating Service, 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.

-- Harshit
Source: StackOverflow