This tutorial will walk you through the steps required to install and configure the Cinder CSI driver on your Kubernetes cluster. Please note, Cinder CSI may also be installed on Kubernetes using helm charts.
Cinder is the open source block storage service that is part of open source OpenStack project - an open source platform to run your virtual machines. Cinder has drivers to interface with various open source and commercial enterprise storage solutions. Running Kubernetes alongside an OpenStack deployment can advantageous. If you have Cinder configured for block storage then you could also use it to provision block storage for your Kubernetes cluster.
To use Cinder with Kubernetes, the required Cinder CSI driver needs to be installed within the Kubernetes Cluster along with an encrypted OpenStack RC configuration for accessing the OpenStack Cloud.
The first step is to clone the cinder repository from GitHub to a host that that has Kubectl installed and can access your Kubernetes cluster.
xxxxxxxxxxgit clone https://github.com/kubernetes/cloud-provider-openstack.gitOnce the repository has been cloned a new Kubernetes Secret must be created that contains the OpenStack RC for connecting to the OpenStack cloud.
Within the cloned directory navigate to the manifest files for the CSI driver cloud-provider-openstack/manifestscinder-csi-plugin/``. In the the CSI driver folder you will need to create the secret which contains the RC file of our OpenStack cloud. Once the file has been created it needs to be converted to base64.
If you have a properly configured OpenStack RC file for your OpenStack cloud, copy it to this directory. Make sure it has all the parameters below properly configured.
Otherwise, create the OpenStack RC file by running the command below:
xxxxxxxxxx[root@master00 cinder-csi-plugin]# cat cloud.conf[Global]username = YOUR_USERpassword = YOUR_PASSWORDdomain-name = defaultauth-url = https://YOUR_DU_URL/keystone/v3tenant-id = YOUR_TENANT_IDregion = YOUR_REGIONSave and close the file.
Use the command below to encrypt your file with base64 so it can be use as a secret.
xxxxxxxxxxcat cloud.conf | base64 |tr -d '\n'W0dsb2JhbF0KdXNlcm5hbWUgPSBZT1VSX1VTRVIKcGFzc3dvcmQgPSBZT1VSX1BBU1NXT1JECmRvbWFpbi1uYW1lID0gZGVmYXVsdAphdXRoLXVybCA9IGh0dHBzOi8vWU9VUl9EVV9VUkwva2V5c3RvbmUvdjMKdGVuYW50LWlkID0gWU9VUl9URU5BTlRfSUQKcmVnaW9uID0gWU9VUl9SRUdJT04KUse VI or VIM to copy the contents of the encoded OpenStack RC configuration and add the string into the data field of the csi-secret-cinderplugin.yamlfile.
root@master00 cinder-csi-plugin# cat csi-secret-cinderplugin.yaml# This YAML file contains secret objects,# which are necessary to run csi cinder plugin.kindSecretapiVersionv1metadata namecloud-config namespacekube-systemdata cloud.confW0dsb2JhbF0KdXNlcm5hbWUgPSBZT1VSX1VTRVIKcGFzc3dvcmQgPSBZT1VSX1BBU1NXT1JECmRvbWFpbi1uYW1lID0gZGVmYXVsdAphdXRoLXVybCA9IGh0dHBzOi8vWU9VUl9EVV9VUkwva2V5c3RvbmUvdjMKdGVuYW50LWlkID0gWU9VUl9URU5BTlRfSUQKcmVnaW9uID0gWU9VUl9SRUdJT04KThe secret can now be added to the Kubernetes Cluster. To do this apply the cs-secret-cinderplugin.yaml file using Kubectl , this will create a secret name cloud-config in kube-system namespace.
xxxxxxxxxxkubectl create -f manifests/cinder-csi-plugin/csi-secret-cinderplugin.yamlThe next step is to apply the remaining manifest files to deploy the csi-cinder controller and related plugins.
The manifests will create a set of cluster roles, cluster role bindings, and StatefulSets to communicate with OpenStack and the Cinder service.
Apply all of the manifests using Kubectl Apply at the parent directory of the cloned Cinder repository.
xxxxxxxxxx$ kubectl -f manifests/cinder-csi-plugin/ applyTo validate the CSI driver is installed and running, run the following and look for the cinder pods in the output.
xxxxxxxxxx$ kubectl get pods -n kube-systemcsi-cinder-controllerplugin-0 6/6 Running 6 8dcsi-cinder-nodeplugin-4w6w6 3/3 Running 3 8dcsi-cinder-nodeplugin-gk5nf 3/3 Running 3 8dTo get information about CSI Drivers running in a cluster
xxxxxxxxxx$ kubectl get csidrivers.storage.k8s.ioNAME CREATED ATcinder.csi.openstack.org 2019-07-29T09:02:40ZOnce the the Cinder CSI driver is installed a Storage Class needs to be setup to enable consumption of the driver. We will be using the following Cinder Storage Class yaml file for this. Save the file as storage-class.yaml.
xxxxxxxxxxapiVersionstorage.k8s.io/v1kindStorageClassmetadata namecinder-example annotations storageclass.kubernetes.io/is-default-class"true"provisionercinder.csi.openstack.orgCreate the storage class using Kubectl
xxxxxxxxxxkubectl create -f storage-class.yaml