← Back to Blog

Using BizflyCloud Volume as a Persistent Volume for a K8s Cluster — BizFlyCloud Volume CSI

If you're running applications or services on the K8s platform, especially Stateful applications, you're probably no stranger to using Persistent Volume Claims (PVC) or Persistent Volumes (PV) to store data for applications across restarts or deletions.

What problem does this solve?

There are many ways to create and use PV and PVC, like using OpenStack's Cinder, NFS, or plugins from third-party providers. Each approach has its own pros and cons.

In today's post I'll show you how to use a Disk on the BizflyCloud platform to automatically create a Persistent Volume for a PVC when requested. I'll install the BizFly Cloud Volume CSI driver for Kubernetes onto the K8s cluster I'm using so I can create StorageClasses. Once we have a StorageClass, we just need to point a PVC at this StorageClass and K8s will automatically create PVs of the corresponding size to hold this PVC. Most major cloud providers like AWS, GCP, or Azure have plugins that support creating things this same way, so once you understand this post you can fully apply it to other Cloud providers.

Prerequisites

  • A Kubernetes cluster
  • A BizflyCloud account with enough permission to create disks.

Installation

Creating a secret

The install steps are fairly simple — just follow the documentation guide. First we need to create a secret containing the info to create the disk resource on the cloud.

apiVersion: v1
kind: Secret
metadata:
 name: bizflycloud
 namespace: kube-system
stringData:
 application_credential_id: "your_application_credential_id"
 application_credential_secret: "your_application_credential_secret"
 tenant_id: "your_tenant_id"
 region: "your_region" # HN, HCM

Here you'll create a secret named bizflycloud in the kube-system namespace, containing info about the application id, application secret, tenant_id or project_id, and the region where you want the disk to get created. Bizfly currently has 2 regions: Hanoi and Ho Chi Minh City.

To get the application credential info, go to manage.bizflycloud.vn/account/security and create a new Credential.

You'll then get the Application's ID and secret

To get the tenant_id, go to the API manage.bizflycloud.vn/account/api/users/info and find the tenant_id key.

Deploying the CSI Plugin

Creating the CSI Plugin

kubectl apply -f https://raw.githubusercontent.com/bizflycloud/csi-bizflycloud/master/manifest/plugin/csi-driver.yaml

Adding RBAC for the controller plugin and node plugin

kubectl apply -f https://raw.githubusercontent.com/bizflycloud/csi-bizflycloud/master/manifest/plugin/csi-bizflycloud-controllerplugin-rbac.yaml
kubectl apply -f https://raw.githubusercontent.com/bizflycloud/csi-bizflycloud/master/manifest/plugin/csi-bizflycloud-nodeplugin-rbac.yaml

Installing the CSI Statefulset and Daemonset

kubectl apply -f https://raw.githubusercontent.com/bizflycloud/csi-bizflycloud/master/manifest/plugin/csi-bizflycloud-controllerplugin.yaml
kubectl apply -f https://raw.githubusercontent.com/bizflycloud/csi-bizflycloud/master/manifest/plugin/csi-bizflycloud-nodeplugin.yaml

So we've created the necessary components — next let's create the StorageClass. Create a file storageClasses.yaml with the following content:

---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: premium-hdd
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: volume.csi.bizflycloud.vn
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
parameters:
  category: premium
  type: HDD
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: premium-ssd
provisioner: volume.csi.bizflycloud.vn
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
parameters:
  category: premium
  type: SSD
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: enterprise-hdd
provisioner: volume.csi.bizflycloud.vn
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
parameters:
  category: enterprise
  type: HDD
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: enterprise-ssd
provisioner: volume.csi.bizflycloud.vn
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
parameters:
  category: enterprise
  type: SSD

Here we create 4 storage classes corresponding to 4 different disk types at different speeds, Premium => Enterprise — there's also a Dedicated disk type, which you can add similarly. With the yaml file above, we set the default disk type to hdd-premium, so a PVC without a StorageClass set will default to hdd-premium. Let's apply the file above to get the storageclasses

kubectl apply -f storageClasses.yaml

So we've finished installing the CSI that supports creating PVs corresponding to PVCs. Next, let's test whether everything works as expected.

Trying it out

To test this, let's create a stateful application using a PVC — in this example it'll be Redis using the bitnami helm chart.

Once the helm chart is installed, we can see the pvcs have been claimed against the auto-generated PVs, as shown

So if you don't set StorageClassName, the PVC defaults to the hdd-premium StorageClass

Note: Volume size should be a number divisible by 10

Pros

  • More convenient for managing resources.
  • A variety of disk types to choose from (HDD, SSD) at different speeds.
  • Can integrate with the Cloud's backup service to secure data.
  • ...

Cons

  • More expensive.
  • Requires the admin to have some specific knowledge about the service being used on that Cloud.

Wrapping up

Hope this post helps you out at work at some point.

References

If you're running into technical challenges or need help with systems, DevOps tools, I'm confident I can help. Get in touch at hoangviet.io.vn

Have thoughts on this?

I'd love to hear your perspective. Send me a message.

Get in touch