|
| 1 | +# Kubevirt CSI driver |
| 2 | + |
| 3 | +The Kubevirt CSI driver is made for a guest cluster deployed on top of Spectro Cloud Palette VMO, and enables it to provision Persistent Volumes from the host VMO cluster. This CSI driver is deployed on the guest cluster. It will contact the host VMO cluster to orchestrate the hot-plugging of disks to VMs running the guest cluster, which will appear as PVCs inside Kubernetes. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Prerequisites |
| 9 | + |
| 10 | +- A host Palette VMO cluster. |
| 11 | +- A guest Kubernetes cluster deployed with VMO VMs, using Palette Agent Mode. |
| 12 | +- Palette Agent mode must be configured to set the hostname of the OS to match the name of the VM (using the `NAME` tag, see Usage section). |
| 13 | + |
| 14 | + |
| 15 | +## Parameters |
| 16 | + |
| 17 | +To deploy the Kubevirt CSI Driver pack, you need to set at least the following parameters in the pack's YAML. |
| 18 | + |
| 19 | +| Name | Description | Type | Default Value | Required | |
| 20 | +| --- | --- | --- | --- | --- | |
| 21 | +| `deployment.driver.infraClusterNamespace` | The namespace in the host VMO cluster in which the VMs for this guest cluster run | String | virtual-machines | Yes | |
| 22 | +| `deployment.infraClusterKubeconfig.k8sAPIendpoint` | The Kubernetes API endpoint of the host VMO cluster | String | `https://vmo-cluster.company.local:6443` | Yes | |
| 23 | +| `deployment.infraClusterKubeconfig.token` | Base64-encoded token from the kubevirt-csi-secret secret in the namespace where the VMs are running in the host VMO cluster | String | - | Yes | |
| 24 | +| `storageClasses[*].infraStorageClassName` | Name of the storageclass in the host VMO cluster that this storageclass should link to | String | spectro-storage-class | Yes | |
| 25 | + |
| 26 | + |
| 27 | +Review the [README](https://github.com/kubevirt/csi-driver/blob/main/README.md) for more details. |
| 28 | + |
| 29 | +## Upgrade |
| 30 | + |
| 31 | +To update the Kubevirt CSI Driver, deploy a newer version of the pack. |
| 32 | + |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +To use the Kubevirt CSI Driver pack, first create a new [add-on cluster profile](https://docs.spectrocloud.com/profiles/cluster-profiles/create-cluster-profiles/create-addon-profile/), Click "Add New Pack" and search for the **Kubevirt CSI Driver** pack in the Palete Community Registry. |
| 37 | + |
| 38 | +Then we need to configure the sections in the pack YAML: |
| 39 | +* The `deployment.driver.infraClusterNamespace` parameter needs to match the namespace in the host VMO cluster that the VMs of the guest cluster will be running in. |
| 40 | +* The `deployment.infraClusterKubeconfig` section requires preparation on the host VMO cluster. The administrator of the host VMO cluster needs to first deploy the "Kubevirt CSI Driver Infra add-on" pack to the host VMO cluster. In that pack, the namespace you want to use in this pack needs to be included. |
| 41 | +* The `deployment.infraClusterKubeconfig.k8sAPIendpoint` parameter can be retrieved from the "Overview" tab of the host VMO cluster in Palette. Use the value of the "Kubernetes API" field on that tab. |
| 42 | +* The `deployment.infraClusterKubeconfig.token` parameter can be retrieved by the administrator of the host VMO cluster after applying the "Kubevirt CSI Driver Infra add-on" pack to the host VMO cluster. The administrator can run the following command to retrieve the token: |
| 43 | +```bash |
| 44 | +kubectl get secret kubevirt-csi-secret -n <namespace> -o json | jq .data.token |
| 45 | +``` |
| 46 | +* The output of the command will be a base64-encoded string. Put that string as-is into the `deployment.infraClusterKubeconfig.token` parameter. |
| 47 | +* Finally, review the `deployment.storageClasses` section. Typically, the host VMO cluster will have 1 storageclass for virtual machines and the name of that storageclass depends on the type of storage used in the VMO cluster. The administrator of the host VMO cluster can provide the correct name for this storageclass. Enter that name in the `parameters.infraStorageClassName` section of the example "kubevirt" storageclass. |
| 48 | + |
| 49 | +### VM deployment |
| 50 | +Once you have configured the pack, you can deploy it to a cluster. Note that you must use Palette Agent-mode clusters for this, and use specific preparation to set up the Agent-mode VMs. The hostname in the OS of each VM must match the name of the VM inside VMO. In order to automate this, we can set the `name` tag during registration of the VM. The following userdata for the VM can be used to automatically configure and register the VM with Palette as an agent-mode edge host, including the correct `name` tag: |
| 51 | +``` |
| 52 | +#cloud-config |
| 53 | +ssh_pwauth: True |
| 54 | +chpasswd: { expire: False } |
| 55 | +password: spectro |
| 56 | +disable_root: false |
| 57 | +packages: |
| 58 | + - jq |
| 59 | + - conntrack |
| 60 | +write_files: |
| 61 | + - path: /tmp/user-data |
| 62 | + owner: 'root:root' |
| 63 | + permissions: '0755' |
| 64 | + content: | |
| 65 | + #cloud-config |
| 66 | + install: |
| 67 | + reboot: true |
| 68 | + poweroff: false |
| 69 | + stylus: |
| 70 | + site: |
| 71 | + edgeHostToken: [registration token here] |
| 72 | + paletteEndpoint: api.console.spectrocloud.com |
| 73 | + tags: |
| 74 | + name: %NAME% |
| 75 | +runcmd: |
| 76 | + - | |
| 77 | + mkdir -p /system/oem; mkdir -p /oem; mkdir -p /usr/local/cloud-config; mkdir -p /opt/spectrocloud/state |
| 78 | + curl --location --output /tmp/palette-agent-install.sh https://github.com/spectrocloud/agent-mode/releases/latest/download/palette-agent-install.sh |
| 79 | + chmod +x /tmp/palette-agent-install.sh |
| 80 | + export USERDATA=/tmp/user-data |
| 81 | + sed -i "s/%NAME%/$(hostname)/" /tmp/user-data |
| 82 | + sudo --preserve-env /tmp/palette-agent-install.sh |
| 83 | +``` |
| 84 | + |
| 85 | +### Snapshot support |
| 86 | +In order to use this CSI for snapshots, the following `VolumeSnapshotClass` can be created (manually, not part of this pack), through deploying the Volume Snapshot Controller pack: |
| 87 | +``` |
| 88 | +apiVersion: snapshot.storage.k8s.io/v1 |
| 89 | +kind: VolumeSnapshotClass |
| 90 | +metadata: |
| 91 | + name: kubevirt-csi-snapclass |
| 92 | +driver: csi.kubevirt.io |
| 93 | +deletionPolicy: Delete |
| 94 | +``` |
| 95 | + |
| 96 | +In the default pack configuration, the VolumeSnapshotClass in the guest cluster will be mapped to the default VolumeSnapshotClass in the host VMO cluster (assuming that VolumeSnapshotClass in the host VMO cluster contains the `snapshot.storage.kubernetes.io/is-default-class: "true"` annotation). If there is no default VolumeSnapshotClass in the host VMO cluster, or if multiple exist, a mapping can be configured in the `deployment.driver.infraStorageClassEnforcement` section of the pack. Review the information [here](https://github.com/kubevirt/csi-driver/blob/main/docs/snapshot-driver-config.md) on how to map VolumeSnapshotClasses to those in the host VMO cluster. |
| 97 | + |
| 98 | +## References |
| 99 | + |
| 100 | +- [Kubevirt CSI driver Github](https://github.com/kubevirt/csi-driver) |
| 101 | +- [Storage classes and Snapshot classes mapping](https://github.com/kubevirt/csi-driver/blob/main/docs/snapshot-driver-config.md) |
0 commit comments