> For the complete documentation index, see [llms.txt](https://docs.trilio.io/kubernetes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trilio.io/kubernetes/appendix/storage/csi-drivers/hostpath-for-tvk.md).

# HostPath Storage for T4K

HostPath is 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 (T4K).

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 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 k8s 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 **Default** namespace

   ```
   ./deploy.sh
   ```
5. Wait for the installation to complete and verify if 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 and VolumeSnapshot Class for Hostpath
   * **StorageClass:**

     ```
     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
     ```
   * **VolumeSnapshotClass:**
7. This step we need to use the API version based on K8s/OCP Version.
   1. OCP 4.3/k8s 1.16 : `apiVersion: snapshot.storage.k8s.io/`**`v1alpha1`**
   2. OCP 4.4/K8s 1.17+ : `apiVersion: snapshot.storage.k8s.io/`**`v1beta1`**
8. ```
   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
   ```

   ```
   apiVersion: snapshot.storage.k8s.io/v1beta1
   kind: VolumeSnapshotClass
   metadata:
     name: default-snapshot-class
   driver: hostpath.csi.k8s.io
   deletionPolicy: Delete
   ```
9. Create a test volume eg: task-pv-claim
   1. ```
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: task-pv-claim
      spec:
        storageClassName: csi-hostpath-sc
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 50Mi
      ```
10. Create a snapshot of task-pv-claim
    1. 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
       ```
    2. If using 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

       ```
11. Verify if snapshot and volume snapshot content shows created snapshot.

```
oc get volumesnapshot
oc get volumesnapshotcontent
```

```
kubectl get volumesnapshot
kubectl get volumesnapshotcontent
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.trilio.io/kubernetes/appendix/storage/csi-drivers/hostpath-for-tvk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
