|
| 1 | +# Kubernetes v1.29: VolumeAttributesClass for Volume Modification |
| 2 | + |
| 3 | +**Authors**: Sunny Song(Google) |
| 4 | + |
| 5 | +The v1.29 release of Kubernetes introduced an alpha feature to support modify volume by changing VolumeAttributesClass that was assigned to a PersistentVolumeClaim (PVC). With the feature enabled, Kubernetes can handle updates of volume attributes other than capacity. Allowing volume attributes to be changed without managing it through different provider's APIs directly simplifies the current flow. |
| 6 | + |
| 7 | +You can read VolumeAttributesClass in the Kubernetes documentation for more details about how to use that, or you can read on to learn about why the Kubernetes project is supporting this feature. |
| 8 | + |
| 9 | + |
| 10 | +## VolumeAttributesClass |
| 11 | + |
| 12 | +The new resource.k8s.io/v1alpha1 API group provides two new types: |
| 13 | + |
| 14 | +**VolumeAttributesClass** |
| 15 | + |
| 16 | +Represents a specification of mutable volume attributes defined by the CSI driver. The class can be specified during dynamic provisioning of PersistentVolumeClaims, and changed in the PersistentVolumeClaim spec after provisioning. |
| 17 | + |
| 18 | +**ModifyVolumeStatus** |
| 19 | + |
| 20 | +Represents the status object of ControllerModifyVolume operation. |
| 21 | + |
| 22 | +With this alpha feature enabled, the spec of PersistentVolumeClaim defines VolumeAttributesClassName that are used in the PVC. At volume provisioning, CreateVolume operation will apply the parameters in the VolumeAttributesClass along with the parameters in the StorageClass. |
| 23 | + |
| 24 | +When there is a change of volumeAttributesClassName in the PVC spec, the external-resizer sidecar will get an informer event. Based on the current state of the configuration, the resizer will trigger a CSI ControllerModifyVolume. The diagram below shows the flow: |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +## How to use it |
| 29 | + |
| 30 | +If you want to test the feature whilst it's alpha, you need to enable the relevant feature gate in the kube-controller-manager and the kube-apiserver. Use the --feature-gates command line argument: |
| 31 | + |
| 32 | + |
| 33 | +``` |
| 34 | +--feature-gates="...,VolumeAttributesClass=true" |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | +It also requires the CSI driver has implemented the ModifyVolume API. |
| 39 | + |
| 40 | + |
| 41 | +### User Flow |
| 42 | + |
| 43 | +If you would like to see the feature in action and verify it works fine in your cluster here's what you can try: |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +1. Define a StorageClass and VolumeAttributesClass |
| 48 | + |
| 49 | +``` |
| 50 | +apiVersion: storage.k8s.io/v1 |
| 51 | +kind: StorageClass |
| 52 | +metadata: |
| 53 | + name: csi-sc-example |
| 54 | +provisioner: pd.csi.storage.gke.io |
| 55 | +parameters: |
| 56 | + disk-type: "hyperdisk-balanced" |
| 57 | +volumeBindingMode: WaitForFirstConsumer |
| 58 | +``` |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +``` |
| 63 | +apiVersion: storage.k8s.io/v1alpha1 |
| 64 | +kind: VolumeAttributesClass |
| 65 | +metadata: |
| 66 | + name: silver |
| 67 | +driverName: pd.csi.storage.gke.io |
| 68 | +parameters: |
| 69 | + provisioned-iops: "3000" |
| 70 | + provisioned-throughput: "50" |
| 71 | +``` |
| 72 | + |
| 73 | + |
| 74 | +2. Define and create the PersistentVolumeClaim |
| 75 | + |
| 76 | + ``` |
| 77 | +apiVersion: v1 |
| 78 | +kind: PersistentVolumeClaim |
| 79 | +metadata: |
| 80 | + name: test-pv-claim |
| 81 | +spec: |
| 82 | + storageClassName: csi-sc-example |
| 83 | + volumeAttributesClassName: silver |
| 84 | + accessModes: |
| 85 | + - ReadWriteOnce |
| 86 | + resources: |
| 87 | + requests: |
| 88 | + storage: 64Gi |
| 89 | +``` |
| 90 | + |
| 91 | + |
| 92 | +3. Verify that PersistentVolumeClaims is now provisioned correctly with: |
| 93 | + |
| 94 | + ``` |
| 95 | +kubectl get pvc |
| 96 | +``` |
| 97 | + |
| 98 | + |
| 99 | +4. Create a new VolumeAttributesClass gold: |
| 100 | + |
| 101 | +``` |
| 102 | +apiVersion: storage.k8s.io/v1alpha1 |
| 103 | +kind: VolumeAttributesClass |
| 104 | +metadata: |
| 105 | + name: gold |
| 106 | +driverName: pd.csi.storage.gke.io |
| 107 | +parameters: |
| 108 | + iops: "4000" |
| 109 | + throughput: "60" |
| 110 | +``` |
| 111 | + |
| 112 | + |
| 113 | +5. Update the PVC with the new VolumeAttributesClass and apply: |
| 114 | + |
| 115 | +``` |
| 116 | +apiVersion: v1 |
| 117 | +kind: PersistentVolumeClaim |
| 118 | +metadata: |
| 119 | + name: test-pv-claim |
| 120 | +spec: |
| 121 | + storageClassName: csi-sc-example |
| 122 | + volumeAttributesClassName: gold |
| 123 | + accessModes: |
| 124 | + - ReadWriteOnce |
| 125 | + resources: |
| 126 | + requests: |
| 127 | + storage: 64Gi |
| 128 | +
|
| 129 | +``` |
| 130 | + |
| 131 | + |
| 132 | +6. Verify that PersistentVolumeClaims has the updated VolumeAttributesClass parameters with: |
| 133 | + |
| 134 | +``` |
| 135 | +kubectl describe pvc {PVC_NAME} |
| 136 | +``` |
| 137 | + |
| 138 | +## Next steps |
| 139 | + |
| 140 | +* See the [VolumeAttributesClass KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/3751-volume-attributes-class) for more information on the design |
| 141 | +* You can view or comment on the [project board](https://github.com/orgs/kubernetes-csi/projects/72) for VolumeAttributesClass |
| 142 | +* In order to move this feature towards beta, we need feedback from the community, so here's a call to action: add support to the CSI drivers, try out this feature, consider how it can help with problems that your users are having… |
| 143 | + |
| 144 | + |
| 145 | +## Getting involved |
| 146 | + |
| 147 | +We always welcome new contributors so if you would like to get involved you can join our [Kubernetes Storage Special-Interest-Group](https://github.com/kubernetes/community/tree/master/sig-storage) (SIG). |
| 148 | + |
| 149 | +If you would like to share feedback, you can do so on our [public Slack channel](https://app.slack.com/client/T09NY5SBT/C09QZFCE5). |
| 150 | + |
| 151 | +Special thanks to all the contributors that provided great reviews, shared valuable insight and helped implement this feature (alphabetical order): |
| 152 | + |
| 153 | +* Baofa Fan (calory) |
| 154 | +* Ben Swartzlander (bswartz) |
| 155 | +* Connor Catlett (ConnorJC3) |
| 156 | +* Hemant Kumar (gnufied) |
| 157 | +* Jan Šafránek (jsafrane) |
| 158 | +* Joe Betz (jpbetz) |
| 159 | +* Jordan Liggitt (liggitt) |
| 160 | +* Matthew Cary (mattcary) |
| 161 | +* Michelle Au (msau42) |
| 162 | +* Xing Yang (xing-yang) |
0 commit comments