<p>The use case is like this:</p>
<p>So we have several pods using the same <code>persistentVolumeClaim</code> with the <code>accessMode</code> set to <code>ReadWriteOnce</code> (because the storage class of the <code>PersistentVolume</code> only support <code>ReadWriteOnce</code>).</p>
<p>From <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/</a>,</p>
<pre><code>ReadWriteOnce -- the volume can be mounted as read-write by a single node
</code></pre>
<p>So these pods should be deployed on the same node in order to access the PVC (otherwise they will fail).</p>
<p>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?</p>

Ken Tsoi
<p>With the inter-pod affinity solution as suggested by Chin, I was able to solve the problem:</p>
<p>The following is my <code>Deployment</code> yaml file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-go
  namespace: stage
  labels:
    app: test-go
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test-go
  template:
    metadata:
      labels:
        app: test-go
        service: git
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: service
                operator: In
                values:
                - git
            topologyKey: kubernetes.io/hostname
      containers:
      - name: test-go
        image: registry.gitlab.com/xxxxxxx/test-go
      imagePullSecrets:
        - name: registry-pull-secret
</code></pre>
<p>In the <code>Deployment</code> yaml file, set a label in the pod template <code>spec.template.metadata.labels</code>, and then add <code>podAffinity</code> config based on the label added, set <code>topologyKey</code> to <code>kubernetes.io/hostname</code> so that the pods will be deployed on the same node.</p>
