I have a problem dealing with persistent data from elasticsearch after I shut down and restart my minikube
Requirement:
- CPUS: 4
- Memory: 7000Mbi
- Driver: hyperv (windows - local)
Scenario:
- Deploy elastic to minikube
- Add data to elasticsearch
- Stop minikube
- Start minikube
- Try to get the previous data and then the data not found:
{
"error" : {
"root_cause" : [
{
"type" : "index_not_found_exception",
"reason" : "no such index [data1]",
"resource.type" : "index_or_alias",
"resource.id" : "data1",
"index_uuid" : "_na_",
"index" : "data1"
}
],
"type" : "index_not_found_exception",
"reason" : "no such index [data1]",
"resource.type" : "index_or_alias",
"resource.id" : "data1",
"index_uuid" : "_na_",
"index" : "data1"
},
"status" : 404
}
My minikube's addons enable:
- default-storageclass
- storage-provisioner
My cluster's status is green: "current.health":"GREEN","message":"Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[.ds-ilm-history-5-2024.06.26-000001][0]]]).","previous.health":"YELLOW","reason":"shards started [[.ds-ilm-history-5-2024.06.26-000001][0]]" , "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsea ..."
Here my yaml. I split the instance in several files:
This is for storage_class.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: elastic-local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
reclaimPolicy: Retain
This is for PV.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: elastic-pv
namespace: production
spec:
storageClassName: elastic-local-storage
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /mnt/data
type: DirectoryOrCreate
persistentVolumeReclaimPolicy: Retain
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: elastic-pvc
namespace: production
spec:
storageClassName: elastic-local-storage
resources:
requests:
storage: 1Gi
accessModes:
- ReadWriteOnce
This is for service.yaml:
apiVersion: v1
kind: Service
metadata:
name: elastic
namespace: production
spec:
type: ClusterIP
selector:
app: elastic
ports:
- name: rest
port: 9200
targetPort: 9200
protocol: TCP
- name: inter-node
port: 9300
targetPort: 9300
protocol: TCP
This is for statefulset.yaml:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: elastic
namespace: production
spec:
serviceName: "elastic"
replicas: 1
selector:
matchLabels:
app: elastic
template:
metadata:
labels:
app: elastic
spec:
initContainers:
- name: busybox
image: busybox:musl
imagePullPolicy: Always
command:
[
"sh",
"-c",
"mkdir -p /usr/share/elasticsearch/data && chown 1000:1000 /usr/share/elasticsearch/data",
]
volumeMounts:
- name: elastic-local-storage
mountPath: /usr/share/elasticsearch/data
containers:
- name: elastic
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
imagePullPolicy: Always
env:
- name: ES_JAVA_OPTS # a
value: "-Xmx1g -Xms1g" # b
- name: bootstrap.memory_lock # a
value: "true" # b
- name: discovery.type # a
value: single-node # b
- name: xpack.security.enabled # a
value: "true" # b
- name: xpack.security.http.ssl.enabled
value: "false"
- name: xpack.security.transport.ssl.enabled
value: "false"
- name: xpack.security.authc.api_key.enabled
value: "true"
- name: xpack.monitoring.collection.enabled
value: "true"
- name: xpack.security.enrollment.enabled
value: "true"
- name: xpack.security.authc.token.enabled
value: "true"
- name: ELASTIC_PASSWORD
value: "mypassword"
resources:
limits:
memory: "3000Mi"
cpu: "800m"
requests:
memory: "3000Mi"
cpu: "400m"
ports:
- name: elastic
containerPort: 9200
volumeMounts:
- name: elastic-local-storage
mountPath: /usr/share/elasticsearch/data
volumes:
- name: elastic-local-storage
persistentVolumeClaim:
claimName: elastic-pvc