<p>I have a simple kubernetes cluster setup on GKE. To persist the data for my express web app, I have a mongodb deployment, cluster-ip-service for the mongodb deployment and persistent volume claim running in the cluster. </p>

<p>Users data are being stored and everything works fine until I deleted the mongodb deployment on GKE console. When I try to bring the mongodb deployment back with the command:</p>

<pre><code>kubectl apply -f mongodb-deployment.yaml
</code></pre>

<p>The mongodb deployment and PVC are running again but <strong>all the previous data was lost.</strong></p>

<p>My mongodb deployment yaml file:</p>

<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: database-persistent-volume-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
</code></pre>

<p>My persistent volume claim yaml file:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: mongo
  template:
    metadata:
      labels:
        component: mongo
    spec:
      volumes:
        - name: mongo-storage
          persistentVolumeClaim:
            claimName: database-persistent-volume-claim
      containers:
      - name: mongo
        image: mongo
        ports:
          - containerPort: 27017
        volumeMounts:
          - name: mongo-storage
            mountPath: /var/lib/mongo/data
</code></pre>

<p>Since the data is be stored in persistent volume which is out of the cluster's lifecycle.</p>

<p><strong>Shouldn't the previous data persist and become available when the database deployment is up and running again?</strong> </p>

<p>I think I might be missing something here.</p>

<p>Yes it is possible with the reclaim setting. Please refer this <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#reclaiming" rel="nofollow noreferrer">documentation</a></p>
