|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.27: Volume Group Snapshot Moves to Alpha" |
| 4 | +date: 2023-04-11T10:00:00-08:00 |
| 5 | +slug: kubernetes-1-27-volume-group-snapshot-alpha |
| 6 | +--- |
| 7 | + |
| 8 | +**Author:** Xing Yang (VMware) |
| 9 | + |
| 10 | +Volume Group Snapshot is introduced as an alpha feature in Kubernetes v1.27. The Volume Group Snapshot feature introduces a Kubernetes API that allows users to take a crash consistent snapshot of multiple volumes together. It uses a label selector to group multiple persistent volume claims for snapshotting. This new feature is only supported for CSI Volume Drivers. |
| 11 | + |
| 12 | +## What is Volume Group Snapshot |
| 13 | + |
| 14 | +Some storage systems provide the ability to create a crash consistent snapshot of multiple volumes. A group snapshot represents “copies” from multiple volumes that are taken at the same point-in-time. A group snapshot can be used either to rehydrate new volumes (pre-populated with the snapshot data) or to restore existing volumes to a previous state (represented by the snapshots). |
| 15 | + |
| 16 | +## Why add Volume Group Snapshots to Kubernetes? |
| 17 | + |
| 18 | +The Kubernetes volume plugin system already provides a powerful abstraction that automates the provisioning, attaching, mounting, resizing, and snapshotting of block and file storage. |
| 19 | + |
| 20 | +Underpinning all these features is the Kubernetes goal of workload portability: Kubernetes aims to create an abstraction layer between distributed applications and underlying clusters so that applications can be agnostic to the specifics of the cluster they run on and application deployment requires no “cluster specific” knowledge. |
| 21 | + |
| 22 | +There is already a [VolumeSnapshot API](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/177-volume-snapshot) that provides the ability to take a snapshot of a persistent volume to protect against data loss or data corruption. However, there are other snapshotting functionalities not covered by the VolumeSnapshot API. |
| 23 | +Some storage systems support consistent group snapshots that allow a snapshot to be taken from multiple volumes at the same point-in-time to achieve write order consistency. This can be useful for applications that contain multiple volumes. For example, an application may have data stored in one volume and logs stored in another volume. If snapshots for the data volume and the logs volume are taken at different times, the application will not be consistent and will not function properly if it is restored from those snapshots when a disaster strikes. |
| 24 | + |
| 25 | +It is true that we can quiesce the application first, take an individual snapshot from each volume that is part of the application one after the other, and then unquiesce the application after all the individual snapshots are taken. This way we will get application consistent snapshots. However, application quiesce is time consuming. Sometimes it may not be possible to quiesce an application. Taking individual snapshots one after another may also take longer time compared to taking a consistent group snapshot. Some users may not want to do application quiesce very frequently for these reasons. For example, a user may want to run weekly backups with application quiesce and nightly backups without application quiesce but with consistent group support which provides crash consistency across all volumes in the group. |
| 26 | + |
| 27 | +## Kubernetes Volume Group Snapshots API |
| 28 | + |
| 29 | +Kubernetes Volume Group Snapshots introduce [three new API objects](https://github.com/kubernetes-csi/external-snapshotter/blob/master/client/apis/volumegroupsnapshot/v1alpha1/types.go) for managing snapshots: |
| 30 | + |
| 31 | +VolumeGroupSnapshot |
| 32 | +* Created by a Kubernetes user to request creation of a volume group snapshot for multiple volumes. It contains information about the volume group snapshot operation such as the timestamp when the volume group snapshot was taken and whether it is ready to use. |
| 33 | +The creation and deletion of this object represents a user’s desire to create or delete a cluster resource (a group snapshot). |
| 34 | + |
| 35 | +VolumeGroupSnapshotContent |
| 36 | +* Created by the Snapshot Controller for a dynamically created VolumeGroupSnapshot. It contains information about the volume group snapshot including the volume group snapshot ID. |
| 37 | +This object represents a provisioned resource on the cluster (a group snapshot). |
| 38 | +Once a volume group snapshot is created, the VolumeGroupSnapshotContent object binds to the VolumeGroupSnapshot for which it was created (with a one-to-one mapping). |
| 39 | + |
| 40 | +VolumeGroupSnapshotClass |
| 41 | +* Created by cluster administrators to describe how volume group snapshots should be created. including the driver information, the deletion policy, etc. |
| 42 | +The Volume Group Snapshot objects are defined as CustomResourceDefinitions (CRDs). These CRDs must be installed in a Kubernetes cluster for a CSI Driver to support volume group snapshots. |
| 43 | + |
| 44 | +## Kubernetes Volume Group Snapshots Requirements |
| 45 | +Volume Group Snapshot feature is implemented in the external-snapshotter repo. It contains the following components: |
| 46 | + |
| 47 | +* Kubernetes Volume Group Snapshot CRDs |
| 48 | +* Volume group snapshot controller logic is added to the common snapshot controller. |
| 49 | +* Volume group snapshot validation webhook logic is added to the common snapshot validation webhook. |
| 50 | +* Logic is also added to CSI Snapshotter sidecar controller. |
| 51 | + |
| 52 | +The volume snapshot controller, CRDs, and validation webhook are deployed once per cluster, while the sidecar is bundled with each CSI driver. |
| 53 | + |
| 54 | +Therefore, it makes sense to deploy the volume snapshot controller, CRDs, and validation webhook as a cluster addon. It is strongly recommended that Kubernetes distributors bundle and deploy the volume snapshot controller, CRDs, and validation webhook as part of their Kubernetes cluster management process (independent of any CSI Driver). |
| 55 | + |
| 56 | +### Creating a new VolumeGroupSnapshot with Kubernetes |
| 57 | +Once a VolumeGroupSnapshotClass object is defined and you have volumes you want to snapshot together, you may create a new group snapshot by creating a VolumeGroupSnapshot object. |
| 58 | + |
| 59 | +The source of the group snapshot specifies whether the underlying group snapshot should be dynamically created or if a pre-existing VolumeGroupSnapshotContent should be used. One of the following members in the source must be set. |
| 60 | +* Selector - Selector is a label query over persistent volume claims that are to be grouped together for snapshotting. This labelSelector will be used to match the label added to a PVC. |
| 61 | +* VolumeGroupSnapshotContentName - specifies the name of a pre-existing VolumeGroupSnapshotContent object representing an existing volume group snapshot. |
| 62 | + |
| 63 | +For dynamic provisioning, a selector must be set so that the snapshot controller can find PVCs with the matching labels to be snapshotted together. |
| 64 | + |
| 65 | +``` |
| 66 | +apiVersion: groupsnapshot.storage.k8s.io/v1alpha1 |
| 67 | +kind: VolumeGroupSnapshot |
| 68 | +metadata: |
| 69 | + name: new-group-snapshot-demo |
| 70 | + namespace: demo-namespace |
| 71 | +spec: |
| 72 | + volumeGroupSnapshotClassName: csi-groupSnapclass |
| 73 | + source: |
| 74 | + selector: |
| 75 | + group: myGroup |
| 76 | +``` |
| 77 | + |
| 78 | +In the VolumeGroupSnapshot spec, a user can specify the VolumeGroupSnapshotClass which has the information about which CSI driver should be used for creating the group snapshot. |
| 79 | + |
| 80 | +### Importing an existing group snapshot with Kubernetes |
| 81 | +You can always import an existing group snapshot to Kubernetes by manually creating a VolumeGroupSnapshotContent object to represent the existing group snapshot. Because VolumeGroupSnapshotContent is a non-namespace API object, only a system admin may have the permission to create it. Once a VolumeGroupSnapshotContent object is created, the user can create a VolumeGroupSnapshot object pointing to the VolumeGroupSnapshotContent object. |
| 82 | +``` |
| 83 | +apiVersion: groupsnapshot.storage.k8s.io/v1alpha1 |
| 84 | +kind: VolumeGroupSnapshotContent |
| 85 | +metadata: |
| 86 | + name: pre-existing-group-snap-content1 |
| 87 | +spec: |
| 88 | + driver: com.example.csi-driver |
| 89 | + deletionPolicy: Delete |
| 90 | + source: |
| 91 | + volumeGroupSnapshotHandle: group-snap-id |
| 92 | + volumeGroupSnapshotRef: |
| 93 | + kind: VolumeGroupSnapshot |
| 94 | + name: pre-existing-group-snap1 |
| 95 | + namespace: demo-namespace |
| 96 | +``` |
| 97 | + |
| 98 | +A VolumeGroupSnapshot object should be created to allow a user to use the group snapshot: |
| 99 | +``` |
| 100 | +apiVersion: groupsnapshot.storage.k8s.io/v1alpha1 |
| 101 | +kind: VolumeGroupSnapshot |
| 102 | +metadata: |
| 103 | + name: pre-existing-group-snap1 |
| 104 | + namespace: demo-namespace |
| 105 | +spec: |
| 106 | + snapshotContentName: pre-existing-group-snap-content1 |
| 107 | +``` |
| 108 | + |
| 109 | +Once these objects are created, the snapshot controller will bind them together, and set the field Ready (under Status) to True to indicate the group snapshot is ready to use. |
| 110 | + |
| 111 | +### How to use group snapshot for restore in Kubernetes |
| 112 | +At restore time, the user can request a new PersistentVolumeClaim to be created from a VolumeSnapshot object that is part of a VolumeGroupSnapshot. This will trigger provisioning of a new volume that is pre-populated with data from the specified snapshot. The user should repeat this until all volumes are created from all the snapshots that are part of a group snapshot. |
| 113 | + |
| 114 | +## As a storage vendor, how do I add support for group snapshots to my CSI driver? |
| 115 | +To implement the volume group snapshot feature, a CSI driver MUST: |
| 116 | +* Implement a new group controller server. |
| 117 | +* Implement group controller RPCs: `CreateVolumeGroupSnapshot`, `DeleteVolumeGroupSnapshot`, and `GetVolumeGroupSnapshot`. |
| 118 | +* Add group controller capability `CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT`. |
| 119 | + |
| 120 | +See the CSI spec and the Kubernetes-CSI Driver Developer Guide for more details. |
| 121 | + |
| 122 | +Although Kubernetes poses as little prescriptive on the packaging and deployment of a CSI Volume Driver as possible, it provides a suggested mechanism to deploy a containerized CSI driver to simplify the process. |
| 123 | + |
| 124 | +As part of this recommended deployment process, the Kubernetes team provides a number of sidecar (helper) containers, including the external-snapshotter sidecar container which has been updated to support volume group snapshot. |
| 125 | + |
| 126 | +The external-snapshotter watches the Kubernetes API server for the `VolumeGroupSnapshotContent` object and triggers `CreateVolumeGroupSnapshot` and `DeleteVolumeGroupSnapshot` operations against a CSI endpoint. |
| 127 | + |
| 128 | +## What are the limitations? |
| 129 | +The alpha implementation of volume group snapshots for Kubernetes has the following limitations: |
| 130 | +* Restore is achieved by creating a new PVC from a VolumeSnapshot that is part of a VolumeGroupSnapshot. |
| 131 | +* Does not support reverting an existing PVC to an earlier state represented by a snapshot that is part of a group snapshot (only supports provisioning a new volume from a snapshot). |
| 132 | +* No application consistency guarantees beyond any guarantees provided by the storage system (e.g. crash consistency). |
| 133 | + |
| 134 | +## What’s next? |
| 135 | +Depending on feedback and adoption, the Kubernetes team plans to push the CSI Group Snapshot implementation to Beta in either 1.28 or 1.29. Some of the features we are interested in supporting include volume replication, replication group, volume placement, application quiescing, changed block tracking, and more. |
| 136 | + |
| 137 | +## How can I learn more? |
| 138 | +The code repository for volume group snapshot APIs and controller is here: https://github.com/kubernetes-csi/external-snapshotter |
| 139 | + |
| 140 | +Check out additional documentation on the group snapshot feature here: https://kubernetes-csi.github.io/docs/ |
| 141 | + |
| 142 | +## How do I get involved? |
| 143 | +This project, like all of Kubernetes, is the result of hard work by many contributors from diverse backgrounds working together. We offer a huge thank you to the contributors who stepped up these last few quarters to help the project reach alpha: |
| 144 | +* Alex Meade ([ameade](https://github.com/ameade)) |
| 145 | +* Ben Swartzlander ([bswartz](https://github.com/bswartz)) |
| 146 | +* Humble Devassy Chirammal ([humblec](https://github.com/humblec)) |
| 147 | +* James Defelice ([jdef](https://github.com/jdef)) |
| 148 | +* Jan Šafránek ([jsafrane](https://github.com/jsafrane)) |
| 149 | +* Jing Xu ([jingxu97](https://github.com/jingxu97)) |
| 150 | +* Michelle Au ([msau42](https://github.com/msau42)) |
| 151 | +* Niels de Vos ([nixpanic](https://github.com/nixpanic)) |
| 152 | +* Rakshith R ([Rakshith-R](https://github.com/Rakshith-R)) |
| 153 | +* Raunak Shah ([RaunakShah](https://github.com/RaunakShah)) |
| 154 | +* Saad Ali ([saad-ali](https://github.com/saad-ali)) |
| 155 | +* Thomas Watson ([rbo54](https://github.com/rbo54)) |
| 156 | +* Xing Yang ([xing-yang](https://github.com/xing-yang)) |
| 157 | +* Yati Padia ([yati1998](https://github.com/yati1998)) |
| 158 | + |
| 159 | +We also want to thank everyone who has helped review the [KEP](https://github.com/kubernetes/enhancements/pull/1551), the [CSI spec PR](https://github.com/container-storage-interface/spec/pull/519), and other PRs. |
| 160 | + |
| 161 | +For those interested in getting involved with the design and development of CSI or any part of the Kubernetes Storage system, join the Kubernetes Storage Special Interest Group (SIG). We always welcome new contributors. |
| 162 | + |
| 163 | +We also hold regular Data Protection Working Group meetings. New attendees are welcome to join our discussions. |
0 commit comments