Moving to Kubernetes v1beta1 Snapshots
In this post I’ll show you how to move from Kubernetes v1alpha1 snapshots to Kubernetes v1beta1 snapshots for VolumeSnapshotSupport on an existing Kubernetes cluster.
What is this important?
With the release of Kubernetes 1.17, Volume Snapshot support has now moved VolumeSnapshot support from Alpha into Beta. Kubernetes Alpha features are considered untested and can be unstable. Also generally there will be improvements from the community that can lead to breaking changes between releases as we’ve seen with the update in Kubernetes release 1.13. This is one of the reasons Alpha releases are disabled by default and need to be enabled manually using featuregates.
Beta releases on the other hand are enabled by default and testing Beta features is encouraged by the maintainers. When a feature goes Beta, more applications start supporting the new feature, preparing for the GA release. In the case of snapshots we are seeing backup applications, like Portworx to support CSI based snapshots for backups, much in the same sense as we have seen this for VMware environments, using VAAI to offload snapshots to the storage provider. This provides significant improves for backups of larger production scale Kubernetes clusters.
Hopefully that intro got you excited to get your hands on the Beta! If you’re like me and you are still running a Kubernetes cluster with the Alpha version enabled via the featuregates, use the following steps upgrade.
Let’s upgrade to Beta!
Remove v1aplha1 CRDs
The first step to enable the Beta is to remove the Custom Resource Definitions (CRDs) that where used for the Alpha. Make sure that before you remove the Alpha CRDs, that you’ve removed any VolumeSnapshot from the environment. If you didn’t, please follow the steps at the end of this post.
kubectl delete crd volumesnapshotcontents.snapshot.storage.k8s.io kubectl delete crd volumesnapshots.snapshot.storage.k8s.io kubectl delete crd volumesnapshotclasses.snapshot.storage.k8s.io
This effectively has removed v1alpha1 snapshot support from the Kubernetes API.
Enable Kubernetes v1beta1 snapshots
The next step is to enable Kubernetes v1beta1 support on your cluster. These steps are described here, but I’ll go through them below anyways.
First you’ll need to recreate the CRDs for the Beta release.
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
With the Beta CRDs in place, you are ready to provision the Kubernetes Snapshot Controller, as shown below.
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-2.0/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml
And with that the Beta has been enabled.
Moving your YAML to Beta
The next thing you’ll want to do if you are creating snapshots, it to move your YAML files from v1alpha1 to v1beta1. The v1alpha way to create a snapshot looked like this:
apiVersion: snapshot.storage.k8s.io/v1alpha1 kind: VolumeSnapshot metadata: name: mariadb-snapshot spec: snapshotClassName: pure-snapshotclass source: name: data-wordpress-mariadb-0 kind: PersistentVolumeClaim
I’ve highlighted the differences for between v1aplha1 and v1beta1 (shown below).
apiVersion: snapshot.storage.k8s.io/v1beta1 kind: VolumeSnapshot metadata: name: mariadb-snapshot spec: volumeSnapshotClassName: pure-snapshotclass source: persistentVolumeClaimName: data-wordpress-mariadb-0
Now that you’ve changed your YAML, you’re ready to use Kubernetes v1beta1 snapshots.
A bit too quick removing the CRDs?
A bit to eager to remove the CRDs? And now you’re stuck with some VolumeSnapshots that you can’t use or delete (don’t ask how I know…). You can remove those, using the following steps:
kubectl get volumesnapshotcontents -A
This will give you a lit of all the
VolumeSnapshotContents objects in your Kubernetes environment. Edit them one by one, using:
kubectl edit volumesnapshotcontents [VolumeSnapshotContents Name]
Remove any finalizers from the definition and same. Next do the same thing for the VolumeSnapshots:
kubectl get volumesnapshot -A kubectl edit volumesnapshot [VolumeSnapshots Name]
Now you can continue to delete both the VolumeSnapshots and VolumeSnapshotContents.
Do make sure that you also clean-up any left over snapshots from your storage platform, as removing the finalizers has stopped the CSI driver to do this for you.
2 thoughts on “Moving to Kubernetes v1beta1 Snapshots”
Hey D-Nix! Thanks for the blog post. I’ve been trying to get this off the ground using testdrive and the snapshotcontroller-0 pod is throwing a “pure-snapshotclass” not found. I’m wondering what version of PSO you deployed, or if there is something obvious I’m missing. I’m using helm 1.2.0 and kubernetes version 1.18.4
Install script and YAMLs can be found here: github.com/puresealab/newstack_testdrive
The beta changes are in a separate branch.
I’m also on slack.
I’ll also slack you, but the snapshot v1beta1 are only supported from PSO 6 (github.com/purestorage/pso-csi). If I’m correct your using PSO 5.2, in which case you’ll still have to use the v1alpha1.