animusdx
animusdx

Reputation: 410

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

I have a postgres pod deployed on OpenShift and a PVC that I think that I correctly attached but I could be wrong. This is my PVC and it is correctly Bound -

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

I created the postgres pods with a PGDATA env set to /var/lib/postgresql/pgdata and mounted the PVC like so -

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

I originally tried to attach the PVC to /var/lib/postgresql/data by overwriting the original container volume but it said there was issues with something like mounting directly to that data folder path so that's why I used the pgdata one.

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

The error that I get now is when I try to scale up the pod/add a replica via the DC, it gives the following errors -

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

and

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

Is it because I did an incorrect mount of my PVC? Or do I need to create a new PVC and then manually update the new pod to that newly created PVC?

Upvotes: 3

Views: 3214

Answers (1)

Suresh Vishnoi
Suresh Vishnoi

Reputation: 18373

as you can see the error

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

you are utilizing a block storage as pv which has accessModes of ReadWriteOnce that means at any given time volume could be attached to a single kubernetes node, on that node then, a pod can mount it. now if you want to attach to another pod, you need to remove the existing pod which will make pv to unattach from previous node, reattach to the new node.

for further details persistent-volumes/

Upvotes: 4

Related Questions