简体   繁体   中英

Persistent Storage in Kubernetes does not persist data

In my Kubernetes cluster, on my DB container, my persistent storage (dynamically provisioned on Digital Ocean) does not persist the storage if the pod is deleted.

I have changed the reclaim policy of the storage from Delete to Retain but this does not make a difference.

This is a copy of DB YAML file:

apiVersion: v1
kind: Service
metadata:
  name: db
  namespace: hm-namespace01
    app: app1
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: app1

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hm-pv-claim
  namespace: hm-namespace01
  labels:
    app: app1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: do-block-storage

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1
  namespace: hm-namespace01
  labels:
    app: app1
spec:
  selector:
    matchLabels:
      app: app1
      tier: backend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: app1
        tier: backend
    spec:
      containers:
        - name: app1
          image: postgres:11
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          volumeMounts:
          - name: postgredb
            mountPath: /var/lib/postgresql

      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: hm-pv-claim

You must match your mountPath with the Postgres PGDATA environment variable.

The default value of PGDATA is /var/lib/postgresql/data (not /var/lib/postgresql ).

You need to either adjust your mountPath or set the PGDATA env to match it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM