Skip to main content

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.

info

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.

  1. Refer to Create cluster to create a cluster for dynamic PV provisioning.

  2. Configure kubectl to 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.

info

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:

Apply deployment
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.

  1. First, install the Helm client. Refer to Helm documentation > Install Helm for OS-specific instructions.

  2. Add the official Helm chart repository:

    Add Helm chart repository
    helm repo add cpo https://kubernetes.github.io/cloud-provider-openstack
    Output
    "cpo" has been added to your repositories
    Update repository
    helm repo update
    Output
    Hang tight while we grab the latest from your chart repositories...
    ...Successfully got an update from the "cpo" chart repository
    Update Complete. ⎈Happy Helming!⎈
  3. Deploy the CSI provisioner to your cluster:

    Deploy CSI provisioner using Helm
    helm install cinder-csi cpo/openstack-cinder-csi \
    --version 2.3.0 \
    --set secret.enabled=true \
    --set secret.name=cloud-config \
    --namespace kube-system
    Output
    NAME: 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:

Check resources
kubectl --kubeconfig=$KUBECONFIG get ds,deploy -n kube-system
Expected output
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.

  1. Verify that the StorageClass resources were created after deploying the CSI provisioner:

    Check StorageClass
    kubectl --kubeconfig=$KUBECONFIG get StorageClass -n kube-system
    Expected result
    NAME                             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
  2. Configure allowedTopologies and its matchLabelExpressions field. Set values under key: topology.cinder.csi.openstack.org/zone to the AZ where volumes should be provisioned:

    ItemSetting
    allowedTopologiesConfigure matchLabelExpressions
    matchLabelExpressions under allowedTopologiesSet key: topology.cinder.csi.openstack.org/zone and values: to kr-central-2-a or kr-central-2-b
  3. Download the StorageClass YAML below and add the settings described in step 2. Add allowedTopologies to both StorageClasses created by the CSI provisioner: csi-cinder-sc-delete and csi-cinder-sc-retain.

    Example: StorageClass targeting specific AZ
    apiVersion: 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
  4. Apply the modified YAML using the actual filename saved locally:

    Apply modified StorageClass
    kubectl --kubeconfig=$KUBECONFIG apply -f edit-storageclass.yaml
    Expected result
    storageclass.storage.k8s.io/csi-cinder-sc-delete configured
    storageclass.storage.k8s.io/csi-cinder-sc-retain configured
  5. 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​

  1. Create a PVC using the following YAML:

    PVC example
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: pvc-test
    spec:
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 10Gi
    storageClassName: csi-cinder-sc-delete
    Apply PVC
    kubectl --kubeconfig=$KUBECONFIG apply -f pvc-test.yaml
  2. Check the dynamically created PV:

    Check PV and PVC
    kubectl --kubeconfig=$KUBECONFIG get pv,pvc
    Expected output
    NAME                                                        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​

  1. Deploy a pod that mounts the PVC:

    Pod example
    apiVersion: 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-storage
    Apply pod
    kubectl --kubeconfig=$KUBECONFIG apply -f task-pv-pod.yaml
  2. Verify that the volume is mounted:

    Check pod and mount
    kubectl --kubeconfig=$KUBECONFIG get pods
    kubectl --kubeconfig=$KUBECONFIG exec -ti task-pv-pod -- df -h
    Expected output
    NAME          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
  3. This confirms that the pod was successfully created and the PV is properly mounted.