【问题标题】:Unable to attach or mount volumes for Postgres pod replicas on OpenShift无法在 OpenShift 上为 Postgres pod 副本附加或装载卷
【发布时间】:2021-04-28 15:09:35
【问题描述】:

我在 OpenShift 上部署了一个 postgres pod 和一个我认为我正确连接的 PVC,但我可能错了。这是我的 PVC,它已正确绑定 -

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
 name: postgres-pvc
spec:
 accessModes:
   - ReadWriteOnce
 resources:
   requests:
     storage: 1Gi
 storageClassName: xxxxx

我创建了带有 PGDATA env 设置为 /var/lib/postgresql/pgdata 的 postgres pod,并像这样安装了 PVC -

oc set volume dc/postgres --add --name=postgres-pvc --type=persistentVolumeClaim \
    --claim-name=postgres-pvc --mount-path=/var/lib/postgresql/pgdata --containers=postgres

我最初尝试通过覆盖原始容器卷将 PVC 附加到 /var/lib/postgresql/data,但它说存在问题,例如直接安装到 data 文件夹路径,所以这就是我使用 pgdata 的原因。

oc set volume dc/postgres --add --overwrite --name=postgres-volume-1 --type=persistentVolumeClaim \
  --claim-name=postgres-pvc --mount-path=/var/lib/postgresql/data --containers=postgres

我现在遇到的错误是当我尝试通过 DC 扩大 pod/添加副本时,它会出现以下错误 -

Unable to attach or mount volumes: unmounted volumes=[postgres-pvc], unattached volumes=[postgres-volume-1 postgres-pvc postgres-token-h7jvr]: timed out waiting for the condition

Error while attaching the device pv pvc-b87b49ff-2bce-495c-b17f-b45f51eab27b cannot be attached to the node xx.xx.xxx.xx. Error: PV pvc-b87b49ff-2bce-495c-b17f-b45f51eab27b is already attached to another node xx.xx.xxx.x and there are active pods [postgres-7-6p6sz] using that

是因为我的 PVC 安装不正确吗?还是我需要创建一个新的 PVC,然后手动将新的 pod 更新为新创建的 PVC?

【问题讨论】:

    标签: postgresql docker kubernetes openshift kubernetes-pvc


    【解决方案1】:

    你可以看到错误

    已经连接到另一个节点 xx.xx.xxx.x 并且有活动的 pod [postgres-7-6p6sz] 使用它

    您正在使用块存储作为 pv,其 accessModesReadWriteOnce,这意味着在任何给定时间卷都可以附加到单个 kubernetes 节点,然后在该节点上,可以挂载一个 pod它。 现在如果你想附加到另一个 pod,你需要删除现有的 pod,这将使 pv 从以前的节点取消附加,重新附加到新节点。

    更多详情persistent-volumes/

    【讨论】:

    • 是的,我在进行一些挖掘之后现在看到了。我试图用ReadWriteMany 创建一个新的PVC,但事实证明块存储类只支持ReadWriteOnce。嗯,你碰巧不清楚我应该为 HA 做些什么?我应该只创建新的ReadWriteOnce PVC,然后为每个新副本手动附加它们吗?
    • 我认为,这是 ReadWriteOnce 的警告,我想我建议您检查 statefulset,它创建一个 pod 和它自己的 pvc。
    • 谢谢,我想我需要做更多的阅读来理解它的技术细节。本质上,当使用 StatefulSets 时,这些副本只是备用副本,对吗?由于他们每个人都使用自己的 PVC,我是否需要编写某种类型的侧容器或在这些 pod 之间复制数据的东西?
    • 不用担心:) 这就是应用程序智能的重要性所在。如果有状态应用程序本身不能在其对等点或集群之间复制数据,那么有一些元应用程序可以帮助实现这一目标。我建议您阅读有关 postgres 的运算符模式和特定运算符的信息。
    猜你喜欢
    • 2021-11-26
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多