potatoxchip
potatoxchip

Reputation: 565

PersistentVolume and PersistentVolumeClaim for multiple deployments

I have 3 deployments, a-depl, b-depl, c-depl. Now each of these 3 deployments has a db deployment: a-db-depl, b-db-depl, c-db-depl. Now I want to persist each of these dbs. Do I need to create a single PV for all or a PV for each of the deployments?

I know that PV <-> PVC is 1-to-1 relation. But I dont know about Depl <-> PV. Can someone please help?

As of now, I have no clue, so I am using a single PV for all of the dp deployments

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongo-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/mnt/data/mongo"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongo-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi

Upvotes: 3

Views: 3701

Answers (2)

aballaci
aballaci

Reputation: 1083

How does one run multiple replicas of a pod and have each pod use its own storage volume? A StatefulSet resource, which is specifically tailored to applications where instances of the application must be treated as non-fungible individuals, with each one having a stable name and state.

Upvotes: 3

Arghya Sadhu
Arghya Sadhu

Reputation: 44559

At a time one PV can be bound to only one PVC. So for each of your PVC you need to create a corresponding PV. To automate PV creation you can create a StorageClass and refer that StorageClass in your PVC. StorageClass can dynamically provision a PV for each PVC.

Whether multiple deployments can use the same PVC or PV depends on accessModes of the PVC or PV.

ReadOnlyMany - the volume can be mounted read-only by many nodes

ReadWriteMany- the volume can be mounted as read-write by many nodes

ReadWriteOnce - the volume can be mounted as read-write by a single node

Upvotes: 7

Related Questions