简体   繁体   English

K8s postgres 不持久化数据

[英]K8s postgres not persisting data

I'm aiming to mount a persistent volume onto a postgres stateful set.我的目标是将持久卷安装到 postgres 有状态集上。 To test persistence, I:为了测试持久性,我:

  • deploy the stateful set, with mounted volume ( kubectl apply -f postgres.yml )部署状态集,挂载卷 ( kubectl apply -f postgres.yml )
  • create a table and insert a row创建一个表并插入一行
  • rescale the stateful set to 0, then delete it ( kubectl scale statefulset/postgresql-db --replicas 0 && kubectl delete statefulset/postgresql-db )将有状态集重新缩放为 0,然后将其删除( kubectl scale statefulset/postgresql-db --replicas 0 && kubectl delete statefulset/postgresql-db
  • redeploy the stateful set ( kubectl apply -f postgres.yml )重新部署状态集( kubectl apply -f postgres.yml

In my new deployment the db is empty, I expected the table and data to be persistent, why is this?在我的新部署中,数据库是空的,我希望表和数据是持久的,这是为什么?

I've been following a few articles to do this, notably:我一直在关注一些文章来做到这一点,特别是:

# kubectl apply -f postgres.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: postgres-pv
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/tp/projects/bitbuyer"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgresql-db
spec:
  serviceName: postgresql-db-service
  selector:
    matchLabels:
      app: postgresql-db
  replicas: 1
  template:
    metadata:
      labels:
        app: postgresql-db
    spec:
      containers:
        - name: postgresql-db
          image: postgres:latest
          volumeMounts:
            - name: postgres-pv
              mountPath: /data
          env:
            - name: POSTGRES_PASSWORD
              value: pgpassword
            - name: PGDATA
              value: /data/pgdata
      volumes:
        - name: postgres-pv
          persistentVolumeClaim:
            claimName: postgres-pvc

Issue could be possible due to问题可能是由于

volumeMounts:
- name: postgres-data
  mountPath: /var/lib/postgresql/data
  subPath: pgdata

however this is what i am using for postgres然而,这就是我在 postgres 中使用的

https://github.com/harsh4870/Keycloack-postgres-kube.netes-deployment/blob/main/postgres.yaml https://github.com/harsh4870/Keycloack-postgres-kube.netes-deployment/blob/main/postgres.yaml

apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  ports:
  - name: pgql
    port: 5432
    targetPort: 5432
    protocol: TCP
  selector:
    app: postgres
---
apiVersion: apps/v1  
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: "postgres"
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:9.5
        volumeMounts:
        - name: postgres-data
          mountPath: /var/lib/postgresql/data
          subPath: pgdata
        env:
        - name: POSTGRES_USER
          value: root
        - name: POSTGRES_PASSWORD
          value: password
        - name: POSTGRES_DB
          value: kong
        - name: PGDATA
          value: /var/lib/postgresql/data/pgdata
        ports:
        - containerPort: 5432
      terminationGracePeriodSeconds: 60
  volumeClaimTemplates:
  - metadata:
      name: postgres-data
    spec:
      accessModes:
      - "ReadWriteOnce"
      resources:
        requests:
          storage: 10Gi

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

相关问题 使用 glusterfs 作为存储的 k8s 上的 postgres - postgres on k8s with glusterfs as storage K8s postgres 备份在 S3 复制期间失败 - K8s postgres backup failed during S3 copy 无法将 Spring Boot 连接到 postgres k8s statefulset - Can't connect spring boot to postgres k8s statefulset Zalando postgres 操作员在 k8s 中从外部访问集群 - Zalando postgres operator acces to cluster from outside in k8s K8s 上的 Postgres:mkdir:无法创建目录“/bitnami/postgresql/data”:初始化 PostgreSQL 数据库时权限被拒绝 - Postgres on K8s: mkdir: cannot create directory ‘/bitnami/postgresql/data’: Permission denied while Initializing PostgreSQL database K8S使用卷来保存数据库数据 - K8S use volume to keep DB data Postgresql k8s上的数据无法持久化 - Postgresql data on k8s cannot be made persistent 在 k8s/Skaffold 中为 Postgres 容器映射本地卷和端口绑定 - Mapping local volume and port binding for Postgres container in k8s/Skaffold Postgres / K8S:PANIC 找不到有效的检查点记录 / CrashLoopBackOff - Postgres / K8S : PANIC could not locate a valid checkpoint record / CrashLoopBackOff 来自 K8s 部署 yaml 文件的 Postgres DB URL 字符串 - Postgres DB URL string from a K8s deployment yaml file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM