无法在 OpenShift 上附加或装载 Postgres pod 副本的卷

Unable to attach or mount volumes for Postgres pod replicas on OpenShift

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

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

我创建了 postgres pods 并将 PGDATA env 设置为 /var/lib/postgresql/pgdata 并像这样安装了 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/add 副本时,它给出了以下错误 -

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?

如您所见错误

already attached to another node xx.xx.xxx.x and there are active pods [postgres-7-6p6sz] using that

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

了解更多详情persistent-volumes/