如何在Kubernete中使用AWS EBS挂载Postgresql卷 [英] How to mount a postgresql volume using Aws EBS in Kubernete

查看:113
本文介绍了如何在Kubernete中使用AWS EBS挂载Postgresql卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我首先创建了永久卷(EBS 10G)和相应的永久卷声明.但是,当我尝试按以下方式部署PostgreSQL Pod(yaml文件)时:

测试postgresql.yaml

从pod接收错误:

initdb:目录"/var/lib/postgresql/data"存在但不为空 它包含一个lost + found目录,可能是由于它是一个挂载点. 不建议将挂载点直接用作数据目录. 在安装点下创建一个子目录.

initdb: directory "/var/lib/postgresql/data" exists but is not empty It contains a lost+found directory, perhaps due to it being a mount point. Using a mount point directly as the data directory is not recommended. Create a subdirectory under the mount point.

为什么吊舱无法使用此路径?我已经在minikube上尝试过相同的测试.我没遇到任何问题.

Why the pod can't use this path? I've tried the same tests on minikube. I didn't meet any problem.

  1. 我试图将卷安装目录路径更改为"/var/lib/test/data",该Pod可以运行.我创建了一个新表及其上的一些数据,然后杀死了该容器. Kubernete创建了一个新的Pod.但是新的并没有保留以前的数据和表.

那么在Kubernete中使用Aws EBS正确安装postgresql卷的方法是什么,它允许重新创建的Pod可以重用存储在EBS中的初始数据库?

So what's the way to correctly mount a postgresql volume using Aws EBS in Kubernete, which allows the recreated pods can reuse initial data base stored in EBS?

推荐答案

那么,使用Aws EBS正确安装postgresql卷的方法是什么

So what's the way to correctly mount a postgresql volume using Aws EBS

您在正确的道路上...

You are on a right path...

您收到的错误是因为您要使用装入的卷/的根文件夹作为postgresql数据目录,而postgresql抱怨这样做不是最佳实践,因为它不为空并且内部已经包含一些数据(即lost+found目录).

Error you get is because you want to use root folder of mounted volume / as postgresql Data dir and postgresql complains that it is not best practice to do so since it is not empty and contains already some data inside (namely lost+found directory).

最好在单独的空子文件夹(例如,/postgres)中定位数据目录,并在创建其文件结构时为PostgreSQL提供干净的位置.在minicube上没有得到相同的东西,因为您最有可能装载的主机文件夹内部没有任何内容(为空)并且没有引发此类投诉.

It is far better to locate data dir in separate empty subfolder (/postgres for example) and give postgresql clean slate when creating its file structure. You didn't get same thing on minicube since you most probably mounted host folder that didn't have anything inside (was empty) and didn't trigger such a complaint.

要这样做,您最初需要清空 subPath 您的卷(例如,PV上的空/postgres子文件夹)已安装到吊舱中的相应安装点(/var/lib/posgresql/data).请注意,您可以将subPath和安装点结束文件夹命名为相同的名称,这里它们是不同的,仅作为示例,其中test-db-volume/postgres文件夹将安装在Pod上的/var/lib/postgresql/data文件夹中:

To do so, you would need initially empty subPath of your volume (empty /postgres subfolder on your PV for example) mounted to appropriate mount point (/var/lib/posgresql/data) in your pod. Note that you can name subPath and mount point end folder the same name, they are different here just as an example where test-db-volume/postgres folder would be mounted on pod to /var/lib/postgresql/data folder:

...
volumeMounts:
- mountPath: /var/lib/postgresql/data
  name: test-db-volume
  subPath: postgres
...

这篇关于如何在Kubernete中使用AWS EBS挂载Postgresql卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆