<p>I have a k8s cluster with machines on two different zones. Originally, I have a StatefulSet with PersistentVolumeClaim, and the Pod &amp; PersistentVolume are on zone #1. Now I want the pod to run one zone #2, so I have to move the PersistentVolume to the zone #2 as well.</p>
<p>How can I do so? I know in the different nodes of the <em>same</em> zone things are quite simple - the pod will auto bring the PersistentVolume with it. But I do not know what to do across zones.</p>
<p>Thanks very much for any suggestions!</p>

ch271828n
<p>This is example on <code>GKE</code>, however other cloud providers should have similar options but with different zone names.</p>
<p>You can do it by <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/regional-pd#dynamic-provisioning" rel="nofollow noreferrer">Regional Persistent Disks</a> with specified <a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="nofollow noreferrer">StorageClass</a>. Depends on your needs you can use:</p>
<ul>
<li><strong>Dynamic Provisioning</strong></li>
</ul>
<blockquote>
<p>To enable dynamic provisioning of regional persistent disks, create a <code>StorageClass</code> with the <code>replication-type</code> parameter, and specify <code>zone</code> constraints in <code>allowedTopologies</code>.</p>
</blockquote>
<pre><code>kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: regionalpd-storageclass
provisioner: pd.csi.storage.gke.io
parameters:
  type: pd-standard
  replication-type: regional-pd
volumeBindingMode: WaitForFirstConsumer
allowedTopologies:
- matchLabelExpressions:
  - key: topology.gke.io/zone
    values:
    - europe-west1-b
    - europe-west1-c
</code></pre>
<p>Above example describes a StorageClass named regionalpd-storageclass that uses standard persistent disks and that replicates data to the europe-west1-b and europe-west1-c zones</p>
<ul>
<li><strong>Manual Provisioning</strong></li>
</ul>
<pre><code>gcloud compute disks create \
 gce-disk-1 \
   --size 500Gi \
   --region europe-west1 \
   --replica-zones europe-west1-b,europe-west1-c
</code></pre>
<p>If you would like to create <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes" rel="nofollow noreferrer">Persistent Volume</a> in specific zone you can specify it in <code>storageClass</code> like in this example:</p>
<pre><code>kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: PV-us-central-1a
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-standard
  zone: us-central1-a
</code></pre>
<p>To use specific <code>StorageClass</code> in <code>PersistentVolume</code> or <code>PersistentVolumeClaim</code> you have to use <code>storageClassName</code>.</p>
<p>Below example with <code>volumeClaimTemplates</code> and <code>storageClassName</code></p>
<pre><code>  `volumeClaimTemplates`:
  - metadata:
      name: www
    spec:
      accessModes: [ &quot;ReadWriteOnce&quot; ]
      storageClassName: &quot;my-storage-class&quot;
      resources:
        requests:
          storage: 1Gi
</code></pre>
<p>Regarding moving PV to different zone, you can use <a href="https://kubernetes.io/docs/concepts/storage/volume-snapshots/" rel="nofollow noreferrer">Volume Snapshots</a> or use 3rd party software like <a href="https://github.com/vmware-tanzu/velero" rel="nofollow noreferrer">Velero</a>. You can find many <code>migrating PV</code> tutorials online using <code>Volume Snapshots</code> like <a href="https://hodovi.cc/blog/migrating-kubernetes-persistentvolumes-across-regions-azs-aws/" rel="nofollow noreferrer">Migrating Kubernetes PersistentVolumes across Regions and AZs on AWS</a>.</p>
<p><strong>Additional documentation</strong></p>
<ul>
<li><a href="https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/preexisting-pd" rel="nofollow noreferrer">Using preexisting persistent disks as PersistentVolumes</a></li>
</ul>
