Skip to main content
  1. Blog/

How to Install vSphere CSI Driver on RedHat OpenShift 4.x

·979 words·5 mins·
Author
Marco Escobar
Data protection, Kubernetes, cybersecurity and AI. Hands-on guides from the trenches: Veeam, Kasten, VMware, Oracle, cloud, and whatever I’m breaking in the homelab this week.
Table of Contents
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 1

One question we keep getting lately is how to configure the vSphere CSI driver on OpenShift 4.x without relying on the operator VMware already built, which is only supported for production as of OpenShift 4.10. In this guide we walk through installing and configuring the driver on versions earlier than 4.10 without using the VMware operator.

Introduction
#

As is widely known, you can install the vSphere CSI driver to provision volumes directly as First Class Disks using the datastores configured in the vSphere environment. On top of that, as of version 4.8 there is an OpenShift operator in Preview for installing the CSI driver, which is fully supported for production environments in the latest release, OpenShift 4.10.

OpenShift users generally do not upgrade automatically to the latest OpenShift releases until their applications and the new OpenShift features or versions have a compatible, supported upgrade path. For that reason, this guide covers installing the vSphere CSI driver from the command line.

This guide assumes the reader is familiar with the OpenShift environment and knows how to connect via the command line. In this case we are using OpenShift 4.8.39.

Requirements
#

We will create two files, csi-vsphere.conf and vsphere.conf, which hold the vSphere access credentials:

csi-vsphere.conf

[Global]
# Para conseguir el ID del cluster se debe ejecutar el siguiente comando
# oc get clusterversion -o jsonpath='{.items[].spec.clusterID}{"\n"}'
cluster-id = "5341dc3e-4ea8-4de6-a4fd-f2715c75a0b8"
[VirtualCenter "vcenter.24xsiempre.cl"]
insecure-flag = "true"
user = "SuperUserdevSphere"
password = "SuperDuperPassword"
port = "443"
datacenters = "24xSiempre"
```bash

Fill in the details of your vSphere environment in the fields above:

- cluster-id: the OpenShift cluster ID; run the command noted in the file to obtain it
- VirtualCenter: the vCenter FQDN address
- User: the vCenter user used with OpenShift
- Password: the password for the vCenter user
- Datacenters: the name of the vCenter datacenter

Next we will create the following file:

vsphere.conf

```bash
[Global]
# Para conseguir el ID del cluster se debe ejecutar el siguiente comando
# oc get clusterversion -o jsonpath='{.items[].spec.clusterID}{"\n"}'
cluster-id = "5341dc3e-4ea8-4de6-a4fd-f2715c75a0b8"
[VirtualCenter "vcenter.24xsiempre.cl"]
insecure-flag = "true"
user = "SuperUserdevSphere"
password = "SuperDuperPassword"
port = "443"
datacenters = "24xSiempre"
```bash

Fill in the details of your vSphere environment in the fields above:

- cluster-id: the OpenShift cluster ID; run the command noted in the file to obtain it
- VirtualCenter: the vCenter FQDN address
- User: the vCenter user used with OpenShift
- Password: the password for the vCenter user
- Datacenters: the name of the vCenter datacenter

Once the files are generated, we will create the secrets from them by running the following commands:

```bash
oc create secret generic vsphere-config-secret --from-file=csi-vsphere.conf --namespace=kube-system
oc create configmap cloud-config --from-file=vsphere.conf --namespace=kube-system
```json



How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 2
And to check that they were created correctly, run: ```bash oc get secret vsphere-config-secret --namespace=kube-system oc get configmap cloud-config --namespace=kube-system ```bash
How to Install vSphere CSI Driver on RedHat OpenShift 4.x
Now we will taint all the nodes with the following command: ```bash kubectl taint nodes --all 'node.cloudprovider.kubernetes.io/uninitialized=true:NoSchedule' ```json
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 3
Then we apply the following YAML files: ```bash oc apply -f https://raw.githubusercontent.com/kubernetes/cloud-provider-vsphere/master/manifests/controller-manager/cloud-controller-manager-roles.yaml oc apply -f https://raw.githubusercontent.com/kubernetes/cloud-provider-vsphere/master/manifests/controller-manager/cloud-controller-manager-role-bindings.yaml oc apply -f https://github.com/kubernetes/cloud-provider-vsphere/raw/master/manifests/controller-manager/vsphere-cloud-controller-manager-ds.yaml ```json
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 4
And to confirm the files above were applied correctly, run: ```bash oc describe nodes | grep "ProviderID" ```json
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 5
## vSphere-CSI Installation Now we will install the driver by applying the following files: ```bash oc apply -f https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.1.1/manifests/v2.1.1/vsphere-7.0u1/vanilla/rbac/vsphere-csi-controller-rbac.yaml oc apply -f https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.1.1/manifests/v2.1.1/vsphere-7.0u1/vanilla/deploy/vsphere-csi-node-ds.yaml oc apply -f https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.1.1/manifests/v2.1.1/vsphere-7.0u1/vanilla/deploy/vsphere-csi-controller-deployment.yaml ```json
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 6
Run the following command: ```bash oc get deployments --namespace=kube-system ```text And wait until READY reaches the 1/1 state:
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 7
And we will verify the driver installation on the nodes with the following command: ```bash oc get CSINode ```bash
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 8
## Creating the StorageClass Now we move on to configuring the StorageClass so it uses the vSphere CSI driver. First, in vCenter we create a storage policy, in this case named "Contenedores", which must be associated with the datastore we will use to host our persistent disks:
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 9
Then we edit the following file: ```bash cat << EOF | kubectl apply -f - kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: sc-csi-vsphere annotations: storageclass.kubernetes.io/is-default-class: "false" provisioner: csi.vsphere.vmware.com parameters: StoragePolicyName: "Contenedores" datastoreURL: "ds:///vmfs/volumes/60634600-6fcc5d36-bd83-dcfe07e145f9/" EOF

Where we need to change the following parameters:

  • name: the name we want for the StorageClass.
  • StoragePolicyName: the name of the storage policy we created earlier.
  • datastoreURL: the URL of the vCenter datastore. The info is shown in the image below.
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 10

After applying the changes to the file, we run it in the console and it shows us:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 11

And we can also verify it in the OpenShift console:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 12

Creating a Persistent Disk
#

We will create a persistent disk from the OpenShift console to validate disk creation and deletion with the new StorageClass. In the OpenShift console, go to Storage, PersistentVolumeClaims and click “Create PersistentVolumeClaim”:

  1. Select the StorageClass we created with vSphere CSI
  2. Enter the volume name
  3. Enter the size
  4. Click “Create”
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 13

And we will see the disk created in OpenShift:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 14

On the configured datastore:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 15
How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 16

Now we will delete the disk to confirm everything works correctly:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 17

Confirmation in OpenShift:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 18

Deletion confirmed in vCenter:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 19

Setting the Default StorageClass
#

In the OpenShift console, go to Storage and click “StorageClasses”, where we will see:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 20

As you can see in the image above, the default StorageClass is “thin”, which is created automatically when OpenShift is installed. We select “thin”, then “Edit Annotations”, change the parameter “storageclass.kubernetes.io/is-default-class” to “false”, and save:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 21

And finally, we select our StorageClass that uses the vSphere CSI driver, in this case “sc-csi-vsphere”, click “Edit Annotations”, change the parameter “storageclass.kubernetes.io/is-default-class” to “true”, and save:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 22

Now we can see that our StorageClass is the default one, and every new persistent disk will use it:

How to Install vSphere CSI Driver on RedHat OpenShift 4.x - screenshot 23

So all that is left now is to install Kasten K10 to protect all your applications on OpenShift; this blog has several guides for installing and configuring Kasten K10.

Related posts#

Related