Moving Statefulsets with PV between K8s clusters

5/27/2019

I am looking to migrate from old GKE clusters to the new Alias IP, however I need to migrate my statefulsets and their PersistentVolumeClaims to the new GKE clusters. I can't seem to find a good answer anywhere stating it's possible, but I imagine it should be as long as it's within the same region. Both new/old k8s cluster still in the same GCP Project, and same Region.

I've searched, but can't find an answer and I can't figure out how to recreate the statefulset without creating a new PV.

-- Eric Anderson
cloud
cluster-computing
google-kubernetes-engine
kubernetes

1 Answer

7/22/2019

You might want to look into the Volume Snapshots and volume snapshot content direction.

Similar to how API resources PersistentVolume and PersistentVolumeClaim are used to provision volumes for users and administrators, VolumeSnapshotContent and VolumeSnapshot API resources are provided to create volume snapshots for users and administrators.

A VolumeSnapshotContent is a snapshot taken from a volume in the cluster that has been provisioned by an administrator. It is a resource in the cluster just like a PersistentVolume is a cluster resource.

A VolumeSnapshot is a request for snapshot of a volume by a user. It is similar to a PersistentVolumeClaim.

Example of Volume Snapshot Contents:

apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshotContent metadata:   name: new-snapshot-content-test spec:   snapshotClassName: csi-hostpath-snapclass   source:
    name: pvc-test
    kind: PersistentVolumeClaim   volumeSnapshotSource:
    csiVolumeSnapshotSource:
      creationTime:    1535478900692119403
      driver:          csi-hostpath
      restoreSize:     10Gi
      snapshotHandle:  7bdd0de3-aaeb-11e8-9aae-0242ac110002

Example of VolumeSnapshot:

apiVersion: snapshot.storage.k8s.io/v1alpha1
kind: VolumeSnapshot
metadata:
  name: new-snapshot-test
spec:
  snapshotClassName: csi-hostpath-snapclass
  source:
    name: pvc-test
    kind: PersistentVolumeClaim

Volume Snapshot Alpha for Kubernetes was introduces in v1.12. This feature allows creating/deleting volume snapshots, and the ability to create new volumes from a snapshot natively using the Kubernetes API.

-- VKR
Source: StackOverflow