Configure block storage CSI provisioner
To use persistent volumes in a cluster, you typically need to configure both storage and a PersistentVolume object.
In Kubernetes Engine, you can configure the CSI (Container Storage Interface) provisioner to use KakaoCloud Block Storage as persistent storage. Once the CSI provisioner is configured, you can simply create a PersistentVolumeClaim to dynamically provision persistent volumes.
The CSI provisioner is not supported on Bare Metal Server node pool types.
Prerequisites
Before configuring the CSI provisioner, the following tasks must be completed. These prerequisites need to be performed only once per cluster.
-
Refer to Create cluster to create a cluster for dynamic PV provisioning.
-
Configure
kubectlto manage the cluster. See Configure kubectl control for details.
Step 1. Configure dynamic volume provisioning
To provision persistent volumes dynamically via PersistentVolumeClaims (PVC), deploy KakaoCloud's CSI provisioner.
The block storage CSI provisioner supports multi-AZ clusters. PersistentVolumes and block storage volumes are dynamically provisioned in response to PersistentVolumeClaims that you create.
Choose one of the following methods to deploy the CSI provisioner.
Deploy CSI provisioner using YAML file
Run the following command in your terminal to install the CSI provisioner:
kubectl --kubeconfig=$KUBECONFIG apply -f https://raw.githubusercontent.com/kakaoenterprise/kakaocloud-tutorials/refs/heads/k8se-public-guides/dynamicPV/cinder-csi.yaml
Deploy CSI provisioner using Helm
Use Helm, the Kubernetes package manager, to configure dynamic volume provisioning.
-
First, install the Helm client. Refer to Helm documentation > Install Helm for OS-specific instructions.
-
Add the official Helm chart repository:
Add Helm chart repositoryhelm repo add cpo https://kubernetes.github.io/cloud-provider-openstackOutput"cpo" has been added to your repositoriesUpdate repositoryhelm repo updateOutputHang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "cpo" chart repository
Update Complete. ⎈Happy Helming!⎈ -
Deploy the CSI provisioner to your cluster:
Deploy CSI provisioner using Helmhelm install cinder-csi cpo/openstack-cinder-csi \
--version 2.3.0 \
--set secret.enabled=true \
--set secret.name=cloud-config \
--namespace kube-systemOutputNAME: cinder-csi
LAST DEPLOYED: Mon Mar 13 14:05:04 2023
NAMESPACE: kube-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Use the following storageClass csi-cinder-sc-retain and csi-cinder-sc-delete only for RWO volumes.
Step 2. Verify CSI provisioner deployment
To verify that the CSI provisioner was deployed correctly, run:
kubectl --kubeconfig=$KUBECONFIG get ds,deploy -n kube-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/openstack-cinder-csi-nodeplugin 1 1 1 1 1 `<none>` 3m5s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/openstack-cinder-csi-controllerplugin 1/1 1 1 3m5s
Step 3. (Optional) Provision volumes in specific AZ in multi-AZ cluster
In a multi-AZ cluster, you can restrict volume provisioning to a specific AZ by editing the StorageClass with the appropriate allowedTopologies.
-
Verify that the StorageClass resources were created after deploying the CSI provisioner:
Check StorageClasskubectl --kubeconfig=$KUBECONFIG get StorageClass -n kube-systemExpected resultNAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION
csi-cinder-sc-delete cinder.csi.openstack.org Delete Immediate true
csi-cinder-sc-retain cinder.csi.openstack.org Retain Immediate true -
Configure
allowedTopologiesand itsmatchLabelExpressionsfield. Setvaluesunderkey: topology.cinder.csi.openstack.org/zoneto the AZ where volumes should be provisioned:Item Setting allowedTopologiesConfigure matchLabelExpressionsmatchLabelExpressionsunderallowedTopologiesSet key: topology.cinder.csi.openstack.org/zoneandvalues:tokr-central-2-aorkr-central-2-b -
Download the StorageClass YAML below and add the settings described in step 2. Add
allowedTopologiesto both StorageClasses created by the CSI provisioner:csi-cinder-sc-deleteandcsi-cinder-sc-retain.Example: StorageClass targeting specific AZapiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-cinder-sc-delete
provisioner: cinder.csi.openstack.org
reclaimPolicy: Delete
volumeBindingMode: Immediate
allowVolumeExpansion: true
allowedTopologies:
- matchLabelExpressions:
- key: topology.cinder.csi.openstack.org/zone
values:
- kr-central-2-a
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-cinder-sc-retain
provisioner: cinder.csi.openstack.org
reclaimPolicy: Retain
volumeBindingMode: Immediate
allowVolumeExpansion: true
allowedTopologies:
- matchLabelExpressions:
- key: topology.cinder.csi.openstack.org/zone
values:
- kr-central-2-a -
Apply the modified YAML using the actual filename saved locally:
Apply modified StorageClasskubectl --kubeconfig=$KUBECONFIG apply -f edit-storageclass.yamlExpected resultstorageclass.storage.k8s.io/csi-cinder-sc-delete configured
storageclass.storage.k8s.io/csi-cinder-sc-retain configured -
Confirm that both StorageClass resources were updated successfully.
Step 4. Test dynamic provisioning of persistent volume
Create a PVC (PersistentVolumeClaim) and confirm that a PV (PersistentVolume) is dynamically created and mounted to a pod.
Apply PVC and verify PV creation
-
Create a PVC using the following YAML:
PVC exampleapiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-test
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: csi-cinder-sc-deleteApply PVCkubectl --kubeconfig=$KUBECONFIG apply -f pvc-test.yaml -
Check the dynamically created PV:
Check PV and PVCkubectl --kubeconfig=$KUBECONFIG get pv,pvcExpected outputNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pvc-c2456546-ddc2-4bd6-9d79-35f6ba53e7fc 10Gi RWO Delete Bound default/pvc-test csi-cinder-sc-delete 16s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/pvc-test Bound pvc-c2456546-ddc2-4bd6-9d79-35f6ba53e7fc 10Gi RWO csi-cinder-sc-delete 16s
Create pod using PVC
-
Deploy a pod that mounts the PVC:
Pod exampleapiVersion: v1
kind: Pod
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: pvc-test
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storageApply podkubectl --kubeconfig=$KUBECONFIG apply -f task-pv-pod.yaml -
Verify that the volume is mounted:
Check pod and mountkubectl --kubeconfig=$KUBECONFIG get pods
kubectl --kubeconfig=$KUBECONFIG exec -ti task-pv-pod -- df -hExpected outputNAME READY STATUS RESTARTS AGE
task-pv-pod 1/1 Running 0 53s
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 9.8G 24K 9.8G 1% /usr/share/nginx/html -
This confirms that the pod was successfully created and the PV is properly mounted.