简体   繁体   English

Kubernetes 中的持久化存储不持久化数据

[英]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.在我的 Kubernetes 集群中,在我的数据库容器上,如果删除 pod,我的持久存储(在 Digital Ocean 上动态配置)不会持久存储。

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:这是 DB YAML 文件的副本:

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.您必须将mountPath与 Postgres PGDATA环境变量相匹配。

The default value of PGDATA is /var/lib/postgresql/data (not /var/lib/postgresql ). PGDATA的默认值/var/lib/postgresql/data (不是/var/lib/postgresql )。

You need to either adjust your mountPath or set the PGDATA env to match it.您需要调整mountPath或设置PGDATA env 以匹配它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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