[英]How to mount a postgresql volume using Aws EBS in Kubernete
test-postgresql.yaml 测试postgresql.yaml
Receive the errors from pod: 从pod接收错误:
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. initdb:目录“/ var / lib / postgresql / data”存在但不是空它包含一个lost + found目录,可能是因为它是一个挂载点。 Using a mount point directly as the data directory is not recommended.
建议不要直接使用挂载点作为数据目录。 Create a subdirectory under the mount point.
在挂载点下创建一个子目录。
Why the pod can't use this path? 为什么pod无法使用此路径? I've tried the same tests on minikube.
我在minikube上尝试过相同的测试。 I didn't meet any problem.
我没有遇到任何问题。
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? 那么在Kubernete中使用Aws EBS正确安装postgresql卷的方法是什么,允许重新创建的pod可以重用存储在EBS中的初始数据库?
So what's the way to correctly mount a postgresql volume using Aws EBS
那么使用Aws EBS正确挂载postgresql卷的方法是什么呢?
You are on a right path... 你走在正确的道路上......
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). 你得到的错误是因为你想使用挂载卷的根文件夹
/
作为postgresql数据目录和postgresql抱怨这不是最佳做法,因为它不是空的并且已经包含一些数据(即lost+found
目录)。
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. 最好将数据目录放在单独的空子文件夹(例如
/postgres
)中,并在创建文件结构时给出postgresql clean slate。 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. 你没有在minicube上得到同样的东西,因为你很可能安装了没有任何内部的主机文件夹(是空的)并且没有引发这样的抱怨。
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. 要执行此操作,您最初需要将卷的空子路径 (例如PV上的空
/postgres
子文件夹)安装到您的pod中的相应安装点( /var/lib/posgresql/data
)。 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: 请注意,您可以将subPath和mount point end文件夹命名为相同的名称,它们在这里是不同的,例如
test-db-volume/postgres
文件夹将安装在pod上的/var/lib/postgresql/data
文件夹中:
...
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: test-db-volume
subPath: postgres
...
I fixed this by telling postgres where i want the data base to be created with the PGDATA env. 我通过告诉postgres来解决这个问题,我希望用PGDATA env创建数据库。 It creates the empty directory and inits the DB.
它创建空目录并在数据库中。 If you dont have this then it assumes you want to create it in the room mount directory which for me had the ;ost+found directory that postgres did not like
如果你没有这个,那么它假设你想在房间挂载目录中创建它,对我来说有ost + found目录,postgres不喜欢
containers:
- name: postgres
imagePullPolicy: Always
image: postgres:9.6
ports:
- containerPort: 5432
name: postgres
env:
- name: POSTGRES_DB
value: "mydb"
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-data
this is from dockerhub description... 这是来自dockerhub描述......
PGDATA This optional variable can be used to define another location - like a subdirectory - for the database files.
PGDATA此可选变量可用于为数据库文件定义另一个位置(如子目录)。 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.
默认为/ var / lib / postgresql / data,但如果您使用的数据卷是文件系统挂载点(与GCE持久性磁盘一样),Postgres initdb建议使用子目录(例如/ var / lib / postgresql / data /创建pgdata以包含数据。
so, create one more deeper dicerctory and it works 所以,创建一个更深层次的dicerctory,它的工作原理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.