The use case is like this:
So we have several pods using the same persistentVolumeClaim with the accessMode set to ReadWriteOnce (because the storage class of the PersistentVolume only support ReadWriteOnce).
From https://kubernetes.io/docs/concepts/storage/persistent-volumes/,
ReadWriteOnce -- the volume can be mounted as read-write by a single node
So these pods should be deployed on the same node in order to access the PVC (otherwise they will fail).
I would like to ask if there are any ways to config the deployment yaml file so that they can be deployed on the same node? or are there any ways to solve this problem?
With the inter-pod affinity solution as suggested by Chin, I was able to solve the problem:
The following is my
Deploymentyaml file:In the
Deploymentyaml file, set a label in the pod templatespec.template.metadata.labels, and then addpodAffinityconfig based on the label added, settopologyKeytokubernetes.io/hostnameso that the pods will be deployed on the same node.