我试图将现有的本地 flex 搜索索引加载到 kubernetes (版本- minikube v1.9.2 ) flex 搜索 Pane 中。 kubectl cp localelasticsearhindexdirectory podname:/data/elk/
我最终了解的是,我必须使用 mountpath 和 hostpath 组合来执行此操作。如果要提供自定义索引文件(不是默认索引文件),则必须使用 configMap 覆盖 config / elasticsearch.yml 的 path.data
我做了以下操作,它在安装路径中创建了一个目录,并更新了 config / elasticsearch.yml 文件,但安装路径目录不包含主机路径目录的内容。
我不知道背后的原因。可以让我知道我在做什么错吗?
然后我去了头并手动 使用以下命令将索引从本地主机复制到kubernetes pod
但是后来我尝试进行 flex 搜索,它给了我空结果(即使索引是手动复制的)。
如果我对本地 flex 搜索使用相同的索引(而不是在kubernetes上),则可以得到结果。
有人可以提供一些建议来诊断以下问题吗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
volumeMounts:
- name: storage
mountPath: /data/elk
- name: config-volume
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
subPath: elasticsearch.yml
volumes:
- name: config-volume
configMap:
name: elasticsearch-config
- name: storage
hostPath:
path: ~/elasticsearch-6.6.1/data
---
apiVersion: v1
kind: ConfigMap
metadata:
name: elasticsearch-config
data:
elasticsearch.yml: |
cluster:
name: ${CLUSTER_NAME:elasticsearch-default}
node:
master: ${NODE_MASTER:true}
data: ${NODE_DATA:true}
name: ${NODE_NAME:node-1}
ingest: ${NODE_INGEST:true}
max_local_storage_nodes: ${MAX_LOCAL_STORAGE_NODES:1}
processors: ${PROCESSORS:1}
network.host: ${NETWORK_HOST:_site_}
path:
data: ${DATA_PATH:"/data/elk"}
repo: ${REPO_LOCATIONS:[]}
bootstrap:
memory_lock: ${MEMORY_LOCK:false}
http:
enabled: ${HTTP_ENABLE:true}
compression: true
cors:
enabled: true
allow-origin: "*"
discovery:
zen:
ping.unicast.hosts: ${DISCOVERY_SERVICE:elasticsearch-discovery}
minimum_master_nodes: ${NUMBER_OF_MASTERS:1}
xpack:
license.self_generated.type: basic ```
**service.yaml**
```apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
service: elasticsearch
spec:
ports:
- name: client
port: 9200
protocol: TCP
targetPort: 9200
- name: nodes
port: 9300
protocol: TCP
targetPort: 9300
type: NodePort
selector:
run: elasticsearch```
最佳答案
HostPath with minikube - Kubernetes中的解决方案为我工作。
要将本地目录挂载到minikube(版本-v1.9.2)中的pod中,您必须将该本地目录挂载到minikube中,然后在hostpath中使用minikube挂载路径
(https://minikube.sigs.k8s.io/docs/handbook/mount/)。
minikube mount ~/esData:/indexdata
📁 Mounting host path /esData into VM as /indexdata ...
▪ Mount type: <no value>
▪ User ID: docker
▪ Group ID: docker
▪ Version: 9p2000.L
▪ Message Size: 262144
▪ Permissions: 755 (-rwxr-xr-x)
▪ Options: map[]
▪ Bind Address: 192.168.5.6:55230
🚀 Userspace file server: ufs starting
✅ Successfully mounted ~/esData to /indexdata
📌 NOTE: This process must stay alive for the mount to be accessible ...
您必须在单独的终端中运行minikube挂载,因为它会启动一个进程并一直停留在该进程中,直到您卸载为止。
现在,我不再以原始问题中的“部署”方式进行操作,而是以Statefulset的方式进行处理,但是相同的解决方案也适用于“部署”。
我在安装过程中遇到的另一个问题是 flex 搜索服务器Pod抛出了
java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
。然后,我看到here,我必须使用 initContainers 在/ usr / share / elasticsearch / data / nodes中设置完全权限。请参阅我的最终Yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: elasticsearch
spec:
serviceName: "elasticsearch"
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
initContainers:
- name: set-permissions
image: registry.hub.docker.com/library/busybox:latest
command: ['sh', '-c', 'mkdir -p /usr/share/elasticsearch/data && chown 1000:1000 /usr/share/elasticsearch/data' ]
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
env:
- name: discovery.type
value: single-node
ports:
- containerPort: 9200
name: client
- containerPort: 9300
name: nodes
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
volumes:
- name: data
hostPath:
path: /indexdata
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
service: elasticsearch
spec:
ports:
- port: 9200
name: client
- port: 9300
name: nodes
type: NodePort
selector:
app: elasticsearch
关于elasticsearch - Minikube-无法从 Elasticsearch 获得任何结果,如果它使用现有索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62224475/