Persistent Volume for Postgres Database in Kubernetes Cluster

7/10/2018

I have created a Persistant Disk Claim for my Postgres Database.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: pgdata
  name: pgdata
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
status: {}

Once I delete the cluster, the volume got deleted too. what's the best practice here? Should I save in some other Persistent Disk like GCEPersistentDisk? I dont want to lose the volume even If cluster is deleted and what are the best strategies for deployment?

-- Alamgir Qazi
kubectl
kubernetes
postgresql

1 Answer

7/10/2018

In the PersistenVolume manifest you can set the reclaiming policy (Retain or Delete, there was a third option now deprecated - Recycle):

persistentVolumeReclaimPolicy: Retain

Reference: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#claims-as-volumes

-- Nicola Ben
Source: StackOverflow