# Elasticsearch Data Lost After Restart Minikube & After Restart Pod In Local Minikube

**URL:** <https://discuss.elastic.co/t/elasticsearch-data-lost-after-restart-minikube-after-restart-pod-in-local-minikube/362081>\
**Category:** Elasticsearch\
**Created:** [June 26, 2024, 9:13am UTC](https://discuss.elastic.co/t/elasticsearch-data-lost-after-restart-minikube-after-restart-pod-in-local-minikube/362081 "2024-06-26T09:13:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arfa\_T](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arfa_t/32/135589_2.png) [@Arfa\_T](https://discuss.elastic.co/u/Arfa_T)\
**Post date:** [June 26, 2024, 9:13am UTC](https://discuss.elastic.co/t/elasticsearch-data-lost-after-restart-minikube-after-restart-pod-in-local-minikube/362081/1 "2024-06-26T09:13:18Z")

</div>

I have a problem dealing with persistent data from elasticsearch after I shut down and restart my minikube

Requirement:

1. CPUS: 4
2. Memory: 7000Mbi
3. Driver: hyperv (windows - local)

Scenario:

1. Deploy elastic to minikube
2. Add data to elasticsearch
3. Stop minikube
4. Start minikube
5. Try to get the previous data and then the data not found:

```auto
{
  "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**

```auto
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**

```auto

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:**

```auto
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:**

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Arfa\_T](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arfa_t/32/135589_2.png) [@Arfa\_T](https://discuss.elastic.co/u/Arfa_T)\
**Post date:** [June 26, 2024, 11:20am UTC](https://discuss.elastic.co/t/elasticsearch-data-lost-after-restart-minikube-after-restart-pod-in-local-minikube/362081/3 "2024-06-26T11:20:26Z")

</div>

Can someone help me, please
