Kubernetes postgres PVC data

11/12/2018

I have postgres yaml for deployment with PV/PVC created. In DB I have a lot of info. When I delete Statesfulset postgres and created new one, data is being lost. How can I do to have restored data after creating new Statesfulset ?

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: postgres
spec:
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  podManagementPolicy: Parallel
  updateStrategy:
    type: RollingUpdate  
  template:
    metadata:
      labels:
        app: postgres
    spec:
      hostname: postgres
      containers:
      - name: postgres
        image: postgres
        imagePullPolicy: Always
        restartPolicy: Always
        env:
          - name: "PGDATA"
            value: "/var/lib/postgresql/data"
          - name: "POSTGRES_INITDB_WALDIR"
            value: "/var/lib/postgresql/dblogs/logs"   
        ...
        ports:
        - name: port5432
          containerPort: 5432
        volumeMounts:
        - name: test
          mountPath: /var/lib/postgresql
        - name: postgressecret
          mountPath: /etc/postgressecret
          readonly: true
      volumes:
        - name: postgressecret
          secret:
            secretName: postgressecret 
        - name: test
          persistentVolumeClaim:
            claimName: test              
  volumeClaimTemplates:
  - metadata:
      name: test
      annotations:
        volume.beta.kubernetes.io/storage-class: thin-disk
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 20Gi  
-- user37033
kubernetes
postgresql

0 Answers