3

I've currently set up a PVC with the name minio-pvc and created a deployment based on the stable/minio chart with the values

mode: standalone
replicas: 1
persistence:
  enabled: true
  existingClaim: minio-pvc

What happens if I increase the number of replicas? Do i run the risk of corrupting data if more than one pod tries to write to the PVC at the same time?

baudsp
  • 4,076
  • 1
  • 17
  • 35
vhflat
  • 561
  • 6
  • 19

2 Answers2

1

Don't use deployment for stateful containers. Instead use StatefulSets. StatefulSets are specifically designed for running stateful containers like databases. They are used to persist the state of the container.

Note that each pod is going to bind a separate persistent volume via pvc. There is no possibility of multiple instances of pods writing to same pv. Hope I answered your question.

P Ekambaram
  • 15,499
  • 7
  • 34
  • 59
0

In case you are sticking to Deployments instead of StatefulSets it won't be feasible for multiple replicas to write to the same PVC, since there is no guarantee that the different replicas are scheduled on the same node, and so you might have a pending pod waiting to establish a connection to the volume and fail. The solution is to choose a specific node and have all your replicas run on the same node.

Run the following and assign a label to one of your nodes:

kubectl label nodes <node-name> <label-key>=<label-value>

Say we choose label-key to be labelKey and label-value to be node1. Then you can go ahead and add the following to your YAML file and have the pods scheduled on the same node:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 3
  template:
    spec:
      nodeSelector:
        labelKey: node1
      containers:
      ...
cookiedough
  • 3,552
  • 2
  • 26
  • 51
  • How is this answer related to the question? – Artem Golenyaev Feb 19 '19 at 16:54
  • @ArtemGolenyaev they are asking if multiple replicas can write to the PVC at the same time, which is possible if you enable the nodeSelector like above. I should mention this in the answer, thanks! – cookiedough Feb 19 '19 at 18:21
  • 1
    This is a completely incorrect statement. It depends on the type of storage they are using. Especially, if the use some cloud provider. – Artem Golenyaev Feb 19 '19 at 19:18
  • 1
    They haven't mentioned what kind of storage they are using, so I'm assuming they are using the standard storage type. You are probably talking about the access mode and the question of using Deployment vs StatefulSet. In which case, if the policy is ReadWriteOnce, you will either have to use a StatefulSet or the solution above. See this [link](https://cloud.google.com/kubernetes-engine/docs/concepts/persistent-volumes). @ArtemGolenyaev – cookiedough Feb 19 '19 at 19:35
  • If you have a volume using azure-csi storage with ReadWriteMany, what is the situation then? Can multiple replicas on a standalone deployment share this resilient cloud storage? – Ed Randall May 12 '22 at 11:15