|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +title: "Kubernetes 1.24: Volume Populators Graduate to Beta" |
| 4 | +date: 2022-05-16 |
| 5 | +slug: volume-populators-beta |
| 6 | +--- |
| 7 | + |
| 8 | +**Author:** |
| 9 | +Ben Swartzlander (NetApp) |
| 10 | + |
| 11 | +The volume populators feature is now two releases old and entering beta! The `AnyVolumeDataSouce` feature |
| 12 | +gate defaults to enabled in Kubernetes v1.24, which means that users can specify any custom resource |
| 13 | +as the data source of a PVC. |
| 14 | + |
| 15 | +An [earlier blog article](/blog/2021/08/30-volume-populators-redesigned/) detailed how the |
| 16 | +volume populators feature works. In short, a cluster administrator can install a CRD and |
| 17 | +associated populator controller in the cluster, and any user who can create instances of |
| 18 | +the CR can create pre-populated volumes by taking advantage of the populator. |
| 19 | + |
| 20 | +Multiple populators can be installed side by side for different purposes. The SIG storage |
| 21 | +community is already seeing some implementations in public, and more prototypes should |
| 22 | +appear soon. |
| 23 | + |
| 24 | +Cluster administrations are **strongly encouraged** to install the |
| 25 | +volume-data-source-validator controller and associated `VolumePopulator` CRD before installing |
| 26 | +any populators so that users can get feedback about invalid PVC data sources. |
| 27 | + |
| 28 | +## New Features |
| 29 | + |
| 30 | +The [lib-volume-populator](https://github.com/kubernetes-csi/lib-volume-populator) library |
| 31 | +on which populators are built now includes metrics to help operators monitor and detect |
| 32 | +problems. This library is now beta and latest release is v1.0.1. |
| 33 | + |
| 34 | +The [volume data source validator](https://github.com/kubernetes-csi/volume-data-source-validator) |
| 35 | +controller also has metrics support added, and is in beta. The `VolumePopulator` CRD is |
| 36 | +beta and the latest release is v1.0.1. |
| 37 | + |
| 38 | +## Trying it out |
| 39 | + |
| 40 | +To see how this works, you can install the sample "hello" populator and try it |
| 41 | +out. |
| 42 | + |
| 43 | +First install the volume-data-source-validator controller. |
| 44 | + |
| 45 | +```shell |
| 46 | +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/volume-data-source-validator/v1.0.1/client/config/crd/populator.storage.k8s.io_volumepopulators.yaml |
| 47 | +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/volume-data-source-validator/v1.0.1/deploy/kubernetes/rbac-data-source-validator.yaml |
| 48 | +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/volume-data-source-validator/v1.0.1/deploy/kubernetes/setup-data-source-validator.yaml |
| 49 | +``` |
| 50 | + |
| 51 | +Next install the example populator. |
| 52 | + |
| 53 | +```shell |
| 54 | +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/lib-volume-populator/v1.0.1/example/hello-populator/crd.yaml |
| 55 | +kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/lib-volume-populator/87a47467b86052819e9ad13d15036d65b9a32fbb/example/hello-populator/deploy.yaml |
| 56 | +``` |
| 57 | + |
| 58 | +Your cluster now has a new CustomResourceDefinition that provides a test API named Hello. |
| 59 | +Create an instance of the `Hello` custom resource, with some text: |
| 60 | + |
| 61 | +```yaml |
| 62 | +apiVersion: hello.example.com/v1alpha1 |
| 63 | +kind: Hello |
| 64 | +metadata: |
| 65 | + name: example-hello |
| 66 | +spec: |
| 67 | + fileName: example.txt |
| 68 | + fileContents: Hello, world! |
| 69 | +``` |
| 70 | +
|
| 71 | +Create a PVC that refers to that CR as its data source. |
| 72 | +
|
| 73 | +```yaml |
| 74 | +apiVersion: v1 |
| 75 | +kind: PersistentVolumeClaim |
| 76 | +metadata: |
| 77 | + name: example-pvc |
| 78 | +spec: |
| 79 | + accessModes: |
| 80 | + - ReadWriteOnce |
| 81 | + resources: |
| 82 | + requests: |
| 83 | + storage: 10Mi |
| 84 | + dataSourceRef: |
| 85 | + apiGroup: hello.example.com |
| 86 | + kind: Hello |
| 87 | + name: example-hello |
| 88 | + volumeMode: Filesystem |
| 89 | +``` |
| 90 | +
|
| 91 | +Next, run a Job that reads the file in the PVC. |
| 92 | +
|
| 93 | +```yaml |
| 94 | +apiVersion: batch/v1 |
| 95 | +kind: Job |
| 96 | +metadata: |
| 97 | + name: example-job |
| 98 | +spec: |
| 99 | + template: |
| 100 | + spec: |
| 101 | + containers: |
| 102 | + - name: example-container |
| 103 | + image: busybox:latest |
| 104 | + command: |
| 105 | + - cat |
| 106 | + - /mnt/example.txt |
| 107 | + volumeMounts: |
| 108 | + - name: vol |
| 109 | + mountPath: /mnt |
| 110 | + restartPolicy: Never |
| 111 | + volumes: |
| 112 | + - name: vol |
| 113 | + persistentVolumeClaim: |
| 114 | + claimName: example-pvc |
| 115 | +``` |
| 116 | +
|
| 117 | +Wait for the job to complete (including all of its dependencies). |
| 118 | +
|
| 119 | +```shell |
| 120 | +kubectl wait --for=condition=Complete job/example-job |
| 121 | +``` |
| 122 | + |
| 123 | +And last examine the log from the job. |
| 124 | + |
| 125 | +```shell |
| 126 | +kubectl logs job/example-job |
| 127 | +``` |
| 128 | + |
| 129 | +The output should be: |
| 130 | + |
| 131 | +```terminal |
| 132 | +Hello, world! |
| 133 | +``` |
| 134 | + |
| 135 | +Note that the volume already contained a text file with the string contents from |
| 136 | +the CR. This is only the simplest example. Actual populators can set up the volume |
| 137 | +to contain arbitrary contents. |
| 138 | + |
| 139 | +## How to write your own volume populator |
| 140 | + |
| 141 | +Developers interested in writing new poplators are encouraged to use the |
| 142 | +[lib-volume-populator](https://github.com/kubernetes-csi/lib-volume-populator) library |
| 143 | +and to only supply a small controller wrapper around the library, and a pod image |
| 144 | +capable of attaching to volumes and writing the appropriate data to the volume. |
| 145 | + |
| 146 | +Individual populators can be extremely generic such that they work with every type |
| 147 | +of PVC, or they can do vendor specific things to rapidly fill a volume with data |
| 148 | +if the volume was provisioned by a specific CSI driver from the same vendor, for |
| 149 | +example, by communicating directly with the storage for that volume. |
| 150 | + |
| 151 | +## How can I learn more? |
| 152 | + |
| 153 | +The enhancement proposal, |
| 154 | +[Volume Populators](https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1495-volume-populators), includes lots of detail about the history and technical implementation |
| 155 | +of this feature. |
| 156 | + |
| 157 | +[Volume populators and data sources](/docs/concepts/storage/persistent-volumes/#volume-populators-and-data-sources), within the documentation topic about persistent volumes, |
| 158 | +explains how to use this feature in your cluster. |
| 159 | + |
| 160 | +Please get involved by joining the Kubernetes storage SIG to help us enhance this |
| 161 | +feature. There are a lot of good ideas already and we'd be thrilled to have more! |
| 162 | + |
0 commit comments