gpt4 book ai didi

kubernetes - 在本地在 kubernetes 中安装 postgresql 持久卷时面临的问题

转载 作者:行者123 更新时间:2023-12-02 12:14:42 25 4
gpt4 key购买 nike

我正在尝试使用静态配置在本地 kubernetes 中挂载 postgrsql 持久卷。
这是我创建的 yaml 文件 pv 、 pvc 和 pod

 apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
namespace: manhattan
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 100Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
namespace: manhattan
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 80Mi
---
apiVersion: v1
kind: Pod
metadata:
name: dbr-postgres
namespace: manhattan
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: task-pv-container
image: postgresql:2.0.1
tty: true
volumeMounts:
- mountPath: "/var/lib/pgsql/9.3/data"
name: task-pv-storage
subPath: data
readOnly: false
nodeSelector:
kubernetes.io/hostname: k8s-master

我的卷位于/var/lib/pgsql/9.3/data 但我的 pod 失败,我不想将 mountPath 的位置更改为/var/lib/pgsql/9.3/data/backup

你能建议yaml文件中的任何覆盖选项吗

我不想在这里用新名称创建文件夹。

enter image description here

如果我将 mountPath 更改为/var/lib/pgsql/9.3/data/backup pod 开始运行,但我不希望将数据写入同一目录/var/lib/pgsql/9.3/data

最佳答案

根据来自 dockerhub 的 postgres:9.4 官方文档:

1 .请注意:

Warning: the Docker specific variables will only have an effect if you start the container with a data directory that is empty; any pre-existing database will be left untouched on container startup.



2 . PGDATA环境变量:

This optional variable can be used to define another location - like a subdirectory - for the database files. The default is /var/lib/postgresql/data, but if the data volume you're using is a filesystem mountpoint (like with GCE persistent disks), Postgres initdb recommends a subdirectory (for example /var/lib/postgresql/data/pgdata ) be created to contain the data.



作为解决方法,请引用:
  • 使用 Dockerfile 时的官方文档
  • 稳定的 Helm chart postgresql

  • 您也可以将图像更改为特定的图像 using helm chart :

    From chart version 4.0.0, it is possible to use this chart with the Docker Official PostgreSQL image. Besides specifying the new Docker repository and tag, it is important to modify the PostgreSQL data directory and volume mount point. Basically, the PostgreSQL data dir cannot be the mount point directly, it has to be a subdirectory.


    helm install --name postgres \
    --set image.repository=postgres \
    --set image.tag=10.6 \
    --set postgresqlDataDir=/data/pgdata \
    --set persistence.mountPath=/data/ \
    stable/postgresql

    您可以模板化此 Helm chart 并进行自定义。从另一个角度来看,主要问题是您已经初始化了您的数据库 - 正如您在/var/lib/pgsql/9.3/data/backup 下提到的,所以请验证您的 docker 文件和您的 docker-entrypoint.sh 以找出在哪里问题。

    如果这有帮助,请告诉我。

    关于kubernetes - 在本地在 kubernetes 中安装 postgresql 持久卷时面临的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58524072/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com