首页 > 解决方案 > 将具有 Elasticsearch 索引的本地目录挂载到 Minikube

问题描述

我正在尝试使用 Elasticsearch 移动我的 Springboot 应用程序以minikube上运行。但我想在 Kubernetes 上运行的弹性搜索中重用我使用本地弹性搜索创建的现有索引。

我可以看到一些关于 Persistent Volume 的文档,但我找不到任何关于重用本地目录上现有索引的信息。

有人可以建议一些有关如何在 Kubernetes 上挂载包含 Elasticsearch 索引的现有本地目录的信息。

我正在尝试使用 minikube 在本地运行 Kubernetes 集群。这是我第一次尝试使用 Kubernetes。因此,我并不熟悉它的所有方面。我正在尝试部署一个连接到 Elasticsearch 服务器的 Spring Boot 应用程序。

Elasticsearch 服务器 - 部署.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

标签: elasticsearchkubernetesminikube

解决方案


尝试StatefulSet为 Elasticsearch 创建一个将用作持久卷声明 (PVC)

PVC 参考链接:https ://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/

在有状态集配置中,您需要这样提及volumeMounts

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

这可以帮助您发现旧索引(本地创建)以及新索引!

为了访问这些索引,我建议Service为 Elasticsearch 创建一个负载均衡器。它将生成一个外部 IP 来访问 Kubernetes 集群中的 Elasticsearch 配置和索引。您可以通过将 curl 应用于生成的外部 IP 来访问。


推荐阅读