I am running elastic & kibana in kubernetes, minikube environment locally. I want to preserve the elastic search indices across minikube restarts. It's not important to preserve the indices if the minikube vm is recreated.
How can I change the config so the search indices are stored in a persistent disk either in the vm or on my macbook host?
This is the existing config file for Elastic Search.
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
spec:
selector:
matchLabels:
component: elasticsearch
template:
metadata:
labels:
component: elasticsearch
spec:
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.2.1
env:
- name: discovery.type
value: single-node
ports:
- containerPort: 9200
name: http
protocol: TCP
https://kubernetes.io/docs/concepts/storage/volumes
spec:
containers:
- name: elasticsearch
# 8<-- snip -->8
volumeMounts:
- name: es-data
mountPath: /var/lib/elasticsearch
initContainers:
- name: chown
image: busybox:latest
command:
- chown
- -R
- "1000" # or whatever your "elasticsearch" user-id is
- /var/lib/elasticsearch
volumeMounts:
- name: es-data
mountPath: /var/lib/elasticsearch
volumes:
- name: es-data
hostPath:
path: /some/path/in/minikube
That initContainers
business is because the hostPath
will in 99% of the cases be owned 0:0
but the elasticsearch docker image is USER elasticsearch
(uid 1000, IIRC) and thus does not have permission to chown
the directory that is volume mounted into the container. You'll need to run that chown
command before starting elasticsearch, thus, the initContainer
.