|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.27: Introducing An API For Volume Group Snapshots" |
| 4 | +date: 2023-05-08 |
| 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. |
| 11 | +This feature introduces a Kubernetes API that allows users to take crash consistent |
| 12 | +snapshots for multiple volumes together. It uses a label selector to group multiple |
| 13 | +`PersistentVolumeClaims` for snapshotting. |
| 14 | +This new feature is only supported for [CSI](https://kubernetes-csi.github.io/docs/) volume drivers. |
| 15 | + |
| 16 | +## An overview of volume group snapshots |
| 17 | + |
| 18 | +Some storage systems provide the ability to create a crash consistent snapshot of |
| 19 | +multiple volumes. A group snapshot represents “copies” from multiple volumes that |
| 20 | +are taken at the same point-in-time. A group snapshot can be used either to rehydrate |
| 21 | +new volumes (pre-populated with the snapshot data) or to restore existing volumes to |
| 22 | +a previous state (represented by the snapshots). |
| 23 | + |
| 24 | +## Why add volume group snapshots to Kubernetes? |
| 25 | + |
| 26 | +The Kubernetes volume plugin system already provides a powerful abstraction that |
| 27 | +automates the provisioning, attaching, mounting, resizing, and snapshotting of block |
| 28 | +and file storage. |
| 29 | + |
| 30 | +Underpinning all these features is the Kubernetes goal of workload portability: |
| 31 | +Kubernetes aims to create an abstraction layer between distributed applications and |
| 32 | +underlying clusters so that applications can be agnostic to the specifics of the |
| 33 | +cluster they run on and application deployment requires no cluster specific knowledge. |
| 34 | + |
| 35 | +There is already a [VolumeSnapshot](/docs/concepts/storage/volume-snapshots/) API |
| 36 | +that provides the ability to take a snapshot of a persistent volume to protect against |
| 37 | +data loss or data corruption. However, there are other snapshotting functionalities |
| 38 | +not covered by the VolumeSnapshot API. |
| 39 | + |
| 40 | +Some storage systems support consistent group snapshots that allow a snapshot to be |
| 41 | +taken from multiple volumes at the same point-in-time to achieve write order consistency. |
| 42 | +This can be useful for applications that contain multiple volumes. For example, |
| 43 | +an application may have data stored in one volume and logs stored in another volume. |
| 44 | +If snapshots for the data volume and the logs volume are taken at different times, |
| 45 | +the application will not be consistent and will not function properly if it is restored |
| 46 | +from those snapshots when a disaster strikes. |
| 47 | + |
| 48 | +It is true that you can quiesce the application first, take an individual snapshot from |
| 49 | +each volume that is part of the application one after the other, and then unquiesce the |
| 50 | +application after all the individual snapshots are taken. This way, you would get |
| 51 | +application consistent snapshots. |
| 52 | + |
| 53 | +However, sometimes it may not be possible to quiesce an application or the application |
| 54 | +quiesce can be too expensive so you want to do it less frequently. Taking individual |
| 55 | +snapshots one after another may also take longer time compared to taking a consistent |
| 56 | +group snapshot. Some users may not want to do application quiesce very often for these |
| 57 | +reasons. For example, a user may want to run weekly backups with application quiesce |
| 58 | +and nightly backups without application quiesce but with consistent group support which |
| 59 | +provides crash consistency across all volumes in the group. |
| 60 | + |
| 61 | +## Kubernetes Volume Group Snapshots API |
| 62 | + |
| 63 | +Kubernetes Volume Group Snapshots introduce [three new API |
| 64 | +objects](https://github.com/kubernetes-csi/external-snapshotter/blob/master/client/apis/volumegroupsnapshot/v1alpha1/types.go) |
| 65 | +for managing snapshots: |
| 66 | + |
| 67 | +`VolumeGroupSnapshot` |
| 68 | +: Created by a Kubernetes user (or perhaps by your own automation) to request |
| 69 | +creation of a volume group snapshot for multiple persistent volume claims. |
| 70 | +It contains information about the volume group snapshot operation such as the |
| 71 | +timestamp when the volume group snapshot was taken and whether it is ready to use. |
| 72 | +The creation and deletion of this object represents a desire to create or delete a |
| 73 | +cluster resource (a group snapshot). |
| 74 | + |
| 75 | +`VolumeGroupSnapshotContent` |
| 76 | +: Created by the snapshot controller for a dynamically created VolumeGroupSnapshot. |
| 77 | +It contains information about the volume group snapshot including the volume group |
| 78 | +snapshot ID. |
| 79 | +This object represents a provisioned resource on the cluster (a group snapshot). |
| 80 | +The VolumeGroupSnapshotContent object binds to the VolumeGroupSnapshot for which it |
| 81 | +was created with a one-to-one mapping. |
| 82 | + |
| 83 | +`VolumeGroupSnapshotClass` |
| 84 | +: Created by cluster administrators to describe how volume group snapshots should be |
| 85 | +created. including the driver information, the deletion policy, etc. |
| 86 | + |
| 87 | +These three API kinds are defined as CustomResourceDefinitions (CRDs). |
| 88 | +These CRDs must be installed in a Kubernetes cluster for a CSI Driver to support |
| 89 | +volume group snapshots. |
| 90 | + |
| 91 | +## How do I use Kubernetes Volume Group Snapshots |
| 92 | + |
| 93 | +Volume group snapshots are implemented in the |
| 94 | +[external-snapshotter](https://github.com/kubernetes-csi/external-snapshotter) repository. Implementing volume |
| 95 | +group snapshots meant adding or changing several components: |
| 96 | + |
| 97 | +* Added new CustomResourceDefinitions for VolumeGroupSnapshot and two supporting APIs. |
| 98 | +* Volume group snapshot controller logic is added to the common snapshot controller. |
| 99 | +* Volume group snapshot validation webhook logic is added to the common snapshot validation webhook. |
| 100 | +* Adding logic to make CSI calls into the snapshotter sidecar controller. |
| 101 | + |
| 102 | +The volume snapshot controller, CRDs, and validation webhook are deployed once per |
| 103 | +cluster, while the sidecar is bundled with each CSI driver. |
| 104 | + |
| 105 | +Therefore, it makes sense to deploy the volume snapshot controller, CRDs, and validation |
| 106 | +webhook as a cluster addon. I strongly recommend that Kubernetes distributors |
| 107 | +bundle and deploy the volume snapshot controller, CRDs, and validation webhook as part |
| 108 | +of their Kubernetes cluster management process (independent of any CSI Driver). |
| 109 | + |
| 110 | +### Creating a new group snapshot with Kubernetes |
| 111 | + |
| 112 | +Once a VolumeGroupSnapshotClass object is defined and you have volumes you want to |
| 113 | +snapshot together, you may request a new group snapshot by creating a VolumeGroupSnapshot |
| 114 | +object. |
| 115 | + |
| 116 | +The source of the group snapshot specifies whether the underlying group snapshot |
| 117 | +should be dynamically created or if a pre-existing VolumeGroupSnapshotContent |
| 118 | +should be used. |
| 119 | + |
| 120 | +A pre-existing VolumeGroupSnapshotContent is created by a cluster administrator. |
| 121 | +It contains the details of the real volume group snapshot on the storage system which |
| 122 | +is available for use by cluster users. |
| 123 | + |
| 124 | +One of the following members in the source of the group snapshot must be set. |
| 125 | + |
| 126 | +* `selector` - a label query over PersistentVolumeClaims that are to be grouped |
| 127 | + together for snapshotting. This labelSelector will be used to match the label |
| 128 | + added to a PVC. |
| 129 | +* `volumeGroupSnapshotContentName` - specifies the name of a pre-existing |
| 130 | + VolumeGroupSnapshotContent object representing an existing volume group snapshot. |
| 131 | + |
| 132 | +In the following example, there are two PVCs. |
| 133 | + |
| 134 | +```yaml |
| 135 | +NAME STATUS VOLUME CAPACITY ACCESSMODES AGE |
| 136 | +pvc-0 Bound pvc-a42d7ea2-e3df-11ed-b5ea-0242ac120002 1Gi RWO 48s |
| 137 | +pvc-1 Bound pvc-a42d81b8-e3df-11ed-b5ea-0242ac120002 1Gi RWO 48s |
| 138 | +``` |
| 139 | + |
| 140 | +Label the PVCs. |
| 141 | +```yaml |
| 142 | +% kubectl label pvc pvc-0 group=myGroup |
| 143 | +persistentvolumeclaim/pvc-0 labeled |
| 144 | + |
| 145 | +% kubectl label pvc pvc-1 group=myGroup |
| 146 | +persistentvolumeclaim/pvc-1 labeled |
| 147 | +``` |
| 148 | + |
| 149 | +For dynamic provisioning, a selector must be set so that the snapshot controller can |
| 150 | +find PVCs with the matching labels to be snapshotted together. |
| 151 | + |
| 152 | +```yaml |
| 153 | +apiVersion: groupsnapshot.storage.k8s.io/v1alpha1 |
| 154 | +kind: VolumeGroupSnapshot |
| 155 | +metadata: |
| 156 | + name: new-group-snapshot-demo |
| 157 | + namespace: demo-namespace |
| 158 | +spec: |
| 159 | + volumeGroupSnapshotClassName: csi-groupSnapclass |
| 160 | + source: |
| 161 | + selector: |
| 162 | + matchLabels: |
| 163 | + group: myGroup |
| 164 | +``` |
| 165 | +
|
| 166 | +In the VolumeGroupSnapshot spec, a user can specify the VolumeGroupSnapshotClass which |
| 167 | +has the information about which CSI driver should be used for creating the group snapshot. |
| 168 | +
|
| 169 | +Two individual volume snapshots will be created as part of the volume group snapshot creation. |
| 170 | +
|
| 171 | +```yaml |
| 172 | +snapshot-62abb5db7204ac6e4c1198629fec533f2a5d9d60ea1a25f594de0bf8866c7947-2023-04-26-2:20:4 |
| 173 | +snapshot-2026811eb9f0787466171fe189c805a22cdb61a326235cd067dc3a1ac0104900-2023-04-26-2:20:4 |
| 174 | +``` |
| 175 | + |
| 176 | +### How to use group snapshot for restore in Kubernetes |
| 177 | + |
| 178 | +At restore time, the user can request a new PersistentVolumeClaim to be created from |
| 179 | +a VolumeSnapshot object that is part of a VolumeGroupSnapshot. This will trigger |
| 180 | +provisioning of a new volume that is pre-populated with data from the specified |
| 181 | +snapshot. The user should repeat this until all volumes are created from all the |
| 182 | +snapshots that are part of a group snapshot. |
| 183 | + |
| 184 | +```yaml |
| 185 | +apiVersion: v1 |
| 186 | +kind: PersistentVolumeClaim |
| 187 | +metadata: |
| 188 | + name: pvc0-restore |
| 189 | + namespace: demo-namespace |
| 190 | +spec: |
| 191 | + storageClassName: csi-hostpath-sc |
| 192 | + dataSource: |
| 193 | + name: snapshot-62abb5db7204ac6e4c1198629fec533f2a5d9d60ea1a25f594de0bf8866c7947-2023-04-26-2:20:4 |
| 194 | + kind: VolumeSnapshot |
| 195 | + apiGroup: snapshot.storage.k8s.io |
| 196 | + accessModes: |
| 197 | + - ReadWriteOnce |
| 198 | + resources: |
| 199 | + requests: |
| 200 | + storage: 1Gi |
| 201 | +``` |
| 202 | +
|
| 203 | +## As a storage vendor, how do I add support for group snapshots to my CSI driver? |
| 204 | +
|
| 205 | +To implement the volume group snapshot feature, a CSI driver **must**: |
| 206 | +
|
| 207 | +* Implement a new group controller service. |
| 208 | +* Implement group controller RPCs: `CreateVolumeGroupSnapshot`, `DeleteVolumeGroupSnapshot`, and `GetVolumeGroupSnapshot`. |
| 209 | +* Add group controller capability `CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT`. |
| 210 | + |
| 211 | +See the [CSI spec](https://github.com/container-storage-interface/spec/blob/master/spec.md) |
| 212 | +and the [Kubernetes-CSI Driver Developer Guide](https://kubernetes-csi.github.io/docs/) |
| 213 | +for more details. |
| 214 | + |
| 215 | +a CSI Volume Driver as possible, it provides a suggested mechanism to deploy a |
| 216 | +containerized CSI driver to simplify the process. |
| 217 | + |
| 218 | +As part of this recommended deployment process, the Kubernetes team provides a number of |
| 219 | +sidecar (helper) containers, including the |
| 220 | +[external-snapshotter sidecar container](https://kubernetes-csi.github.io/docs/external-snapshotter.html) |
| 221 | +which has been updated to support volume group snapshot. |
| 222 | + |
| 223 | +The external-snapshotter watches the Kubernetes API server for the |
| 224 | +`VolumeGroupSnapshotContent` object and triggers `CreateVolumeGroupSnapshot` and |
| 225 | +`DeleteVolumeGroupSnapshot` operations against a CSI endpoint. |
| 226 | + |
| 227 | +## What are the limitations? |
| 228 | + |
| 229 | +The alpha implementation of volume group snapshots for Kubernetes has the following |
| 230 | +limitations: |
| 231 | + |
| 232 | +* Does not support reverting an existing PVC to an earlier state represented by |
| 233 | + a snapshot (only supports provisioning a new volume from a snapshot). |
| 234 | +* No application consistency guarantees beyond any guarantees provided by the storage system |
| 235 | + (e.g. crash consistency). See this [doc](https://github.com/kubernetes/community/blob/master/wg-data-protection/data-protection-workflows-white-paper.md#quiesce-and-unquiesce-hooks) |
| 236 | + for more discussions on application consistency. |
| 237 | + |
| 238 | +## What’s next? |
| 239 | + |
| 240 | +Depending on feedback and adoption, the Kubernetes team plans to push the CSI |
| 241 | +Group Snapshot implementation to Beta in either 1.28 or 1.29. |
| 242 | +Some of the features we are interested in supporting include volume replication, |
| 243 | +replication group, volume placement, application quiescing, changed block tracking, and more. |
| 244 | + |
| 245 | +## How can I learn more? |
| 246 | + |
| 247 | +- The [design spec](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/3476-volume-group-snapshot) |
| 248 | + for the volume group snapshot feature. |
| 249 | +- The [code repository](https://github.com/kubernetes-csi/external-snapshotter) for volume group |
| 250 | + snapshot APIs and controller. |
| 251 | +- CSI [documentation](https://kubernetes-csi.github.io/docs/) on the group snapshot feature. |
| 252 | + |
| 253 | +## How do I get involved? |
| 254 | + |
| 255 | +This project, like all of Kubernetes, is the result of hard work by many contributors |
| 256 | +from diverse backgrounds working together. On behalf of SIG Storage, I would like to |
| 257 | +offer a huge thank you to the contributors who stepped up these last few quarters |
| 258 | +to help the project reach alpha: |
| 259 | + |
| 260 | +* Alex Meade ([ameade](https://github.com/ameade)) |
| 261 | +* Ben Swartzlander ([bswartz](https://github.com/bswartz)) |
| 262 | +* Humble Devassy Chirammal ([humblec](https://github.com/humblec)) |
| 263 | +* James Defelice ([jdef](https://github.com/jdef)) |
| 264 | +* Jan Šafránek ([jsafrane](https://github.com/jsafrane)) |
| 265 | +* Jing Xu ([jingxu97](https://github.com/jingxu97)) |
| 266 | +* Michelle Au ([msau42](https://github.com/msau42)) |
| 267 | +* Niels de Vos ([nixpanic](https://github.com/nixpanic)) |
| 268 | +* Rakshith R ([Rakshith-R](https://github.com/Rakshith-R)) |
| 269 | +* Raunak Shah ([RaunakShah](https://github.com/RaunakShah)) |
| 270 | +* Saad Ali ([saad-ali](https://github.com/saad-ali)) |
| 271 | +* Thomas Watson ([rbo54](https://github.com/rbo54)) |
| 272 | +* Xing Yang ([xing-yang](https://github.com/xing-yang)) |
| 273 | +* Yati Padia ([yati1998](https://github.com/yati1998)) |
| 274 | + |
| 275 | +We also want to thank everyone else who has contributed to the project, including others |
| 276 | +who helped review the [KEP](https://github.com/kubernetes/enhancements/pull/1551) |
| 277 | +and the [CSI spec PR](https://github.com/container-storage-interface/spec/pull/519). |
| 278 | + |
| 279 | +For those interested in getting involved with the design and development of CSI or |
| 280 | +any part of the Kubernetes Storage system, join the |
| 281 | +[Kubernetes Storage Special Interest Group](https://github.com/kubernetes/community/tree/master/sig-storage) (SIG). |
| 282 | +We always welcome new contributors. |
| 283 | + |
| 284 | +We also hold regular [Data Protection Working Group meetings](https://docs.google.com/document/d/15tLCV3csvjHbKb16DVk-mfUmFry_Rlwo-2uG6KNGsfw/edit#). |
| 285 | +New attendees are welcome to join our discussions. |
0 commit comments