HostPath CSI Driver for Trilio for Kubernetes

This section describes installation of Hostpath CSI driver

Deprecated Documentation

This document is deprecated and no longer supported. For accurate, up-to-date information, please refer to the documentation for the latest version of Trilio.

HostPath CSI Driver for Trilio for Kubernetes

HostPath is a storage type where volumes refer to directories on the Node (VM/machine) where your Pod is scheduled for running.

In this section, we are going to see how to enable HostPath for your Kubernetes Cluster and test the VolumeSnapshot functionality which is the prerequisite for Trilio for Kubernetes.

Follow the steps below to install and validate the HostPath CSI driver :

  1. Clone the hostpath GitHub repository:

    git clone https://github.com/kubernetes-csi/csi-driver-host-path.git
  2. Go to the specific directory where the installation script is available. This depends on your Kubernetes cluster version

    cd csi-driver-host-path/deploy/kubernetes-1.XX
  3. Skip this step if the Kubernetes version is less than 1.17

    # Change to the latest supported snapshotter version
    $ SNAPSHOTTER_VERSION=v2.0.1
    
    # Apply VolumeSnapshot CRDs
    $ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
    $ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
    $ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
    
    # Create snapshot controller
    $ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/rbac-snapshot-controller.yaml
    $ kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml
  4. Run the shell script based on your cluster OCP/K8s Version. Make sure you install this driver in the Default namespace

    ./deploy.sh
  5. Wait for the installation to complete and verify if the driver is installed correctly.

    Make sure following pods are running
    
    NAME                                                  READY   STATUS      RESTARTS   AGE
    csi-hostpath-attacher-0                               1/1     Running     0          28d
    csi-hostpath-provisioner-0                            1/1     Running     1          28d
    csi-hostpath-resizer-0                                1/1     Running     0          28d
    csi-hostpath-snapshotter-0                            1/1     Running     0          28d
    csi-hostpath-socat-0                                  1/1     Running     0          28d
    csi-hostpathplugin-0                                  3/3     Running     0          28d
  6. Create a Storage Class for Hostpath

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: csi-hostpath-sc
      annotations:
        storageclass.kubernetes.io/is-default-class: "true"
    provisioner: hostpath.csi.k8s.io
    reclaimPolicy: Retain
    volumeBindingMode: Immediate
  7. Create a VolumeSnapshot Class for Hostpath. At this step, we need to use the API version based on K8s/OCP Version.

    • OCP 4.3/k8s 1.16 : apiVersion: snapshot.storage.k8s.io/v1alpha1

      apiVersion: snapshot.storage.k8s.io/v1alpha1
      kind: VolumeSnapshotClass
      metadata:
        annotations:
          snapshot.storage.kubernetes.io/is-default-class: "true"
        name: default-snapshot-class
      snapshotter: hostpath.csi.k8s.io
    • OCP 4.4/K8s 1.17+ : apiVersion: snapshot.storage.k8s.io/v1beta1

      apiVersion: snapshot.storage.k8s.io/v1beta1
      kind: VolumeSnapshotClass
      metadata:
        name: default-snapshot-class
      driver: hostpath.csi.k8s.io
      deletionPolicy: Delete
  8. Create a test volume eg: task-pv-claim

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: task-pv-claim
    spec:
      storageClassName: csi-hostpath-sc
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 50Mi
  9. Create a snapshot of task-pv-claim.

    • If using the Alpha version of the API

      apiVersion: snapshot.storage.k8s.io/v1alpha1
      kind: VolumeSnapshot
      metadata:
       name: new-snapshot-demo
       namespace: default
      spec:
       snapshotClassName: default-snapshot-class
       source:
        name: task-pv-claim
        kind: PersistentVolumeClaim
    • If using the Beta version of the API

      apiVersion: snapshot.storage.k8s.io/v1beta1
      kind: VolumeSnapshot
      metadata:
        name: new-snapshot
      spec:
        volumeSnapshotClassName: default-snapshot-class
        source:
          persistentVolumeClaimName: task-pv-claim
  10. Verify if snapshot and volume snapshot content shows created snapshot.

oc get volumesnapshot
oc get volumesnapshotcontent
kubectl get volumesnapshot
kubectl get volumesnapshotcontent

Last updated