Data is lost after changes are applied to the image

11/6/2019

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.

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

This is a statefulset

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

Thanks in advance.

enter image description here

-- Surat Pyari
amazon-eks
elasticsearch
kubernetes

1 Answer

11/6/2019

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.

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.

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 Ekambaram
Source: StackOverflow