簡體   English   中英

Kubernetes 中的持久化存儲不持久化數據

[英]Persistent Storage in Kubernetes does not persist data

在我的 Kubernetes 集群中,在我的數據庫容器上,如果刪除 pod,我的持久存儲(在 Digital Ocean 上動態配置)不會持久存儲。

我已將存儲的回收策略從刪除更改為保留,但這並沒有什么不同。

這是 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

您必須將mountPath與 Postgres PGDATA環境變量相匹配。

PGDATA的默認值/var/lib/postgresql/data (不是/var/lib/postgresql )。

您需要調整mountPath或設置PGDATA env 以匹配它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM