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 TrilioVault for Kubernetes.
Follow the steps below to install and validate the HostPath CSI driver :
Clone the hostpath GitHub repository:
git clone https://github.com/kubernetes-csi/csi-driver-host-path.git
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
​
Skip this step if volumesnapshot, volumesnapshotcontent, volumesnapshotclass crds are already present on the cluster.
# 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
Run the shell script based on your cluster OCP/K8s Version. Make sure you install this driver in the Default namespace
./deploy.sh
Wait for the installation to complete and verify if the driver is installed correctly.
Make sure following pods are running​NAME READY STATUS RESTARTS AGEcsi-hostpath-attacher-0 1/1 Running 0 28dcsi-hostpath-provisioner-0 1/1 Running 1 28dcsi-hostpath-resizer-0 1/1 Running 0 28dcsi-hostpath-snapshotter-0 1/1 Running 0 28dcsi-hostpath-socat-0 1/1 Running 0 28dcsi-hostpathplugin-0 3/3 Running 0 28d
Create a Storage Class for Hostpath
apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:name: csi-hostpath-scannotations:storageclass.kubernetes.io/is-default-class: "true"provisioner: hostpath.csi.k8s.ioreclaimPolicy: RetainvolumeBindingMode: Immediate
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/v1alpha1kind: VolumeSnapshotClassmetadata:annotations:snapshot.storage.kubernetes.io/is-default-class: "true"name: default-snapshot-classsnapshotter: hostpath.csi.k8s.io
OCP 4.4/K8s 1.17+ : apiVersion: snapshot.storage.k8s.io/v1beta1
apiVersion: snapshot.storage.k8s.io/v1beta1kind: VolumeSnapshotClassmetadata:name: default-snapshot-classdriver: hostpath.csi.k8s.iodeletionPolicy: Delete
Create a test volume eg: task-pv-claim
apiVersion: v1kind: PersistentVolumeClaimmetadata:name: task-pv-claimspec:storageClassName: csi-hostpath-scaccessModes:- ReadWriteOnceresources:requests:storage: 50Mi
Create a snapshot of task-pv-claim.
If using the Alpha version of the API
apiVersion: snapshot.storage.k8s.io/v1alpha1kind: VolumeSnapshotmetadata:name: new-snapshot-demonamespace: defaultspec:snapshotClassName: default-snapshot-classsource:name: task-pv-claimkind: PersistentVolumeClaim
If using the Beta version of the API
apiVersion: snapshot.storage.k8s.io/v1beta1kind: VolumeSnapshotmetadata:name: new-snapshotspec:volumeSnapshotClassName: default-snapshot-classsource:persistentVolumeClaimName: task-pv-claim
Verify if snapshot and volume snapshot content shows created snapshot.
oc get volumesnapshotoc get volumesnapshotcontent
kubectl get volumesnapshotkubectl get volumesnapshotcontent