<p>I am trying to add Elasticsearch to the EKS cluster. But whenever I apply the changes my data is lost. It looks like volume I have attached has been changed and reclaimed.</p>

<pre><code>metadata:
  name: elasticsearch-uat
  labels:
    component: elasticsearch-uat
spec:
  replicas: 1
  serviceName: elasticsearch-uat
  template: 
    metadata:
      ...
    spec:
      initContainers: 
      - name: init-sysctl
        ...
      containers:
      - name: es 
        securityContext:
          capabilities:
            add:
              - IPC_LOCK
        image: 559076975273.dkr.ecr.us-west-2.amazonaws.com/elasticsearch-s3:v2
        env:
        ...
        ports:
        - containerPort: 9200
          name: http
          protocol: TCP
        - containerPort: 9300
          name: transport
          protocol: TCP
        volumeMounts: 
        - mountPath: /data
          name: es-storage-uat
  updateStrategy:
    type: RollingUpdate
  volumeClaimTemplates:
  - metadata:
      namespace: k8
      name: es-storage-uat
    spec:
      storageClassName: gp2
      accessModes: [ ReadWriteOnce ]
      resources:
        requests:
          storage: 2Gi
</code></pre>

<p>This is a statefulset </p>

<p>Please help me to understand this concept. I do not want my data to loose in any condition.</p>

<p>Thanks in advance.</p>

<p><a href="https://i.stack.imgur.com/biMh3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/biMh3.png" alt="enter image description here"></a></p>

Surat Pyari
<p>From pv output it is clear that PersistentVolume reclaim policy is set to Delete. Which means that if the pvc is deleted the PersistentVolume gets auto deleted. You loose the data if the pvc is deleted.</p>

<p>In your case, it is appropriate to use the “Retain” policy. With the “Retain” policy, if a user deletes a PersistentVolumeClaim, the corresponding PersistentVolume is not be deleted.</p>

<p>Further to the above, if you are using dynamic storage then set reclaimPolicy field of the storage class to appropriate value. If no reclaimPolicy is specified when a StorageClass object is created, it will default to Delete. </p>
