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

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

问题描述

  1. 我首先创建了持久卷 (EBS 10G) 和相应的持久卷声明.但是当我尝试如下部署 postgresql pod 时(yaml 文件):

test-postgresql.yaml

从 pod 接收错误:

Receive the errors from pod:

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

为什么pod不能使用这个路径?我在 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 可以运行.我创建了一个新表和一些数据,然后杀死了这个 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 子文件夹)安装到 pod 中的适当安装点 (/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天全站免登陆